строки

проверка mail javascript

14.01.2013 javascript 1 comment , , , , ,

if(EMAIL != ''){

			var checkMail = (
									EMAIL &&
									EMAIL.indexOf('@') > 0 &&
									EMAIL.toLowerCase().match(/^(?:[-a-z\d\+\*\/\?!{}`~_%&'=^$#]+(?:\.[-a-z\d\+\*\/\?!{}`~_%&'=^$#]+)*)@(?:[-a-z\d_]+\.){1,60}[a-z]{2,6}$/)
								) ? true : false;
			
			if(checkMail){
				hideError('EMAIL');
			}else{		
				showError('EMAIL');
				errorArr.push(1);
			}
		}else{
		
			showError('EMAIL');
			errorArr.push(1);
		
		}

CSV Выгрузка

21.11.2012 Bitrix, php, php скрипты , , ,

<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");

	CModule::IncludeModule("iblock");

		$handle = fopen("tb.csv", "r");
		$csv    = array();

		while ( !feof( $handle ) ) {

			$line  = fgets($handle);
			$data  = explode(";", $line);
			$csv[] = $data;

		}

		$rs = new CDBResult;
		$el = new CIBlockElement;

		$rs->InitFromArray($csv);
		$rs->NavStart(1);

		$naumberPageGet = $rs->NavNum;
		$thisPage       = $_GET["PAGEN_".$naumberPageGet];

		if( !isset( $_GET["PAGEN_".$naumberPageGet] ) ){

			$nextPge = "PAGEN_".$naumberPageGet."=2";

		}else{

			if($rs->NavPageCount > $thisPage){
				$thisPage+=1;
				$nextPge = "PAGEN_".$naumberPageGet."=".$thisPage;
			}

		}

		if($rs->IsNavPrint())
		{
			 echo "<p>"; $rs->NavPrint("Элементы"); echo "</p>";
		}

		####
		$clearArray = array();

		$el = new CIBlockElement;

		while($test = $rs->Fetch()){

			$PROP = array();
			$PROP['RATE_GROUP']     = $test[0];
			$PROP['SUM']            = $test[1];
			$PROP['COEFF_DAMAGE'][] = Array("VALUE" => $test[2],"DESCRIPTION" => "");
			$PROP['COEFF_DAMAGE'][] = Array("VALUE" => $test[3],"DESCRIPTION" => "");
			$PROP['COEFF_DAMAGE'][] = Array("VALUE" => $test[4],"DESCRIPTION" => "");
			$PROP['COEFF_DAMAGE'][] = Array("VALUE" => $test[5],"DESCRIPTION" => "");
			$PROP['COEFF_DAMAGE'][] = Array("VALUE" => $test[6],"DESCRIPTION" => "");
			$PROP['COEFF_DAMAGE'][] = Array("VALUE" => $test[7],"DESCRIPTION" => "");

			$arLoadProductArray     = Array(
				"MODIFIED_BY"       => $USER->GetID(), // элемент изменен текущим пользователем
				"IBLOCK_SECTION_ID" => false,          // элемент лежит в корне раздела
				"IBLOCK_ID"         => 34,
				"PROPERTY_VALUES"   => $PROP,
				"NAME"              => $test[0],
				"ACTIVE"            => "Y",            // активен
			);

			// if($PRODUCT_ID = $el->Add($arLoadProductArray))
				// itdbg("New ID: ".$PRODUCT_ID);
			// else
				// itdbg("Error: ".$el->LAST_ERROR,true);

			itdbg($arLoadProductArray,false,2);
			echo '<pre>';
			var_dump($arLoadProductArray);
			echo '</pre>';

		}
		###

		$nPage = $rs->NavPageNomer;

		if($thisPage == $nPage){
			itdbg('exi',true, 2);
		}
?>
		<script>
		function second_passed() {
			window.document.location.href = "<?=$APPLICATION->GetCurPageParam($nextPge, array("PAGEN_".$naumberPageGet,"MUS_IMPORT","MUS_TYPE_PROCEDURE")); ?>";
		}
		setTimeout(second_passed, 1000);
		</script>

Склонение слов с помощью javaScript

27.09.2012 javascript 15 комментариев , ,


function declination(a5, b1, c2, s) { 
 	var words = [a5, b1, c2]; 
	var index = s % 100; 
	if (index >=11 && index <= 14) { index = 0; } 
	else { index = (index %= 10) < 5 ? (index > 2 ? 2 : index): 0; } 
	return(words[index]); 
} 

declination('лет', 'год', 'года', 23)

php

function declination($status= array('','а','ов'), $value){
	$array =array(2,0,1,1,1,2);
	return $status[($value%100>4 && $value%100<20)? 2 : $array[($value%10<5)?$value%10:5]];
	}

Bitrix

use Bitrix\Main\Grid\Declension;
$yearDeclension = new Declension('год', 'года', 'лет');
$yearDeclension->get($year);

Расчет по формуле php

26.09.2012 php, php скрипты No comments ,

Расчет по формуле php

function calculated_formula($elements_formula=array(), $formula='',$default=0){
	if(count($elements_formula)>0 && strlen($formula)>0){		
		$pattern = "/\[([A-Za-z_0-9]*?)\]/i";
		preg_match_all($pattern, $formula, $matches);
		foreach($matches[1] as $elemFormula){
			if(!isset($elements_formula[$elemFormula]) || empty($elements_formula[$elemFormula])){
				$elements_formula[$elemFormula] = $default;
			}
		}
		$replacement = "\$elements_formula$0";
		$result = preg_replace($pattern, $replacement, $formula);
		return eval("return $result;");
	}
}
$test['test1'] = '';
$test['test2'] = 3;
echo calculated_formula($test, '[test1]+[test2]+1',1);

удаление пробелов в строке и замена «,» на «.»

31.08.2012 php, php скрипты No comments

удаление пробелов в строке и замена «,» на «.»

function srtreplaceZPT($var){
	$var =  str_replace(',', ".", $var);
	$cena=preg_replace("/[^x\d|*\.]/","",$var);
	return $cena;
}

ВЫБРАТЬ ИЗ СТРОКИ ТОЛЬКО ЦИФРЫ

30.08.2012 php No comments

preg_replace( "/\D/", '' , '200 000 р.' ) // echo 200000

очистить число
получить число

strstr

30.08.2012 php No comments ,

strstr($keyPostData, "TEST_")

Ищет в строке подстроку