This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Bitrix\Main\Application; | |
$connection = Application::getConnection(); | |
$sqlHelper = $connection->getSqlHelper(); | |
$sql = "SELECT ID FROM b_user WHERE LOGIN = '".$sqlHelper->forSql($login, 50)."'"; | |
//$connection->query($sql, $limit); | |
//$connection->query($sql, $offset, $limit); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(defined('BX_COMP_MANAGED_CACHE')) | |
$GLOBALS['CACHE_MANAGER']->ClearByTag('iblock_id_4'); //clear cache for iblock with ID = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function plural_form($n, $forms) { | |
return $n%10==1&&$n%100!=11?$forms[0]:($n%10>=2&&$n%10<=4&&($n%100<10||$n%100>=20)?$forms[1]:$forms[2]); | |
} | |
//usage | |
$ends = [ | |
"банан", | |
"банана", | |
"бананов" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function isPhone($val){ | |
if (!preg_match('/^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$/iu', $val)) | |
return false; | |
return true; | |
} | |
//allow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Bitrix\Main\Diag\Debug; | |
use Bitrix\Main\Diag\Helper; | |
/*Write in file*/ | |
//Debug::writeToFile($variable, $varName, $file); | |
Debug::writeToFile(['ID' => $ID, 'fields' => $arResult ], null, "log.log"); | |
Debug::dumpToFile(['ID' => $ID, 'fields' => $arResult ], null, "log.log"); | |
/*Time label*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$adress = urlencode("Москва, Тверская улица, дом 7"); | |
$url = "http://geocode-maps.yandex.ru/1.x/?geocode={$adress}"; | |
$content = file_get_contents($url); | |
preg_match("/<pos>(.*?)<\/pos>/", $content, $point); | |
$coords = str_replace(' ', ', ', trim(strip_tags($point[1]))); | |
echo $coords; | |
// результат: 38.241803, 56.300984 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class=frame> | |
<span class="helper"></span><img src="http://jsfiddle.net/img/logo.png" height=250 /> | |
</div> | |
<div class=frame> | |
<span class="helper"></span><img src="http://jsfiddle.net/img/logo.png" height=25 /> | |
</div> | |
<div class=frame> | |
<span class="helper"></span><img src="http://jsfiddle.net/img/logo.png" height=23 /> | |
</div> | |
<div class=frame> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getNumEnding(number, titles) { | |
var cases = [2, 0, 1, 1, 1, 2]; | |
return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ]; | |
} | |
use: | |
getNumEnding(count, ["товар", "товара", "товаров"]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die(); | |
global $APPLICATION; | |
//Если на странице товара | |
if(isset($arResult["VARIABLES"]["ELEMENT_CODE"])) { | |
CModule::IncludeModule("iblock"); | |
//Получаем id раздела товара | |
$rsElement = CIBlockElement::GetList(array("ID" => "ASC"), array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "CODE" => $arResult["VARIABLES"]["ELEMENT_CODE"]), false, array("nTopCount" => 1), array("ID", "IBLOCK_ID", "NAME", "DETAIL_PAGE_URL")); | |
while($obElement = $rsElement->GetNextElement()) { | |
$arItem = $obElement->GetFields(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
function getNumEnding($number, $endingArray) { | |
$number = $number % 100; | |
if ($number>=11 && $number<=19) { | |
$ending=$endingArray[2]; | |
} else { | |
$i = $number % 10; | |
switch ($i) { | |
case (1): $ending = $endingArray[0]; break; | |
case (2): case (3): case (4): $ending = $endingArray[1]; break; |