Архив

Архив раздела ‘PHP’
18 августа 2020 Нет комментариев
function remove_bom($str=""){
	if(substr($str,0,3)==pack('CCC',0xef,0xbb,0xbf)){
		$str=substr($str,3);
	}
	return $str;
}
Categories: PHP Tags:
echo "<ul>";
for($i=0;$i<=count($arResult)-1;$i++){
	$arItemActive=($arResult[$i]['SELECTED'])?' class="active"':'';
	echo "<li".$arItemActive.">";
		echo '<a href="'.$arResult[$i]['LINK'].'">'.$arResult[$i]['TEXT'].'</a>';
		if($arResult[$i]['DEPTH_LEVEL']<$arResult[$i+1]['DEPTH_LEVEL']){
			echo "<ul>\r\n";
		}
		elseif($arResult[$i]['DEPTH_LEVEL']==$arResult[$i+1]['DEPTH_LEVEL']){
			echo "</li>\r\n";
		}
		if($arResult[$i]['DEPTH_LEVEL']>$arResult[$i+1]['DEPTH_LEVEL']){
			echo "</ul>\r\n";
		}
}
echo "</ul>";
Categories: PHP Tags:
define('HTTP_USER','user');
define('HTTP_PASS','pass');
if(isset($_SERVER['PHP_AUTH_USER'])&&($_SERVER['PHP_AUTH_PW']==HTTP_PASS)&&(strtolower($_SERVER['PHP_AUTH_USER'])==HTTP_USER)){
	//success
}
else{
	header('WWW-Authenticate: Basic realm="Authorization required"');
	header('HTTP/1.0 401 Unauthorized');
	echo 'Authenticate required!';
	exit();
}
Categories: PHP Tags:
$date_from=strtotime(date('Y-m-d').' 00:00:00');
Categories: PHP Tags:

Как, например, xml:

if($dir=opendir(ROOT_DIR.IMPORT_DIR)){
	while(false!==($file=readdir($dir))){
		if(is_file(ROOT_DIR.IMPORT_DIR.$file)){
			$offers=@simplexml_load_file(ROOT_DIR.IMPORT_DIR.$file);
			if($offers){
				print_pre($offers);
			}
		}
	}
}

Или csv:

if($dir=opendir(ROOT_DIR.IMPORT_DIR)){
	while(false!==($file=readdir($dir))){
		if(is_file(ROOT_DIR.IMPORT_DIR.$file)){
			if(($handle=fopen(ROOT_DIR.IMPORT_DIR.$file,"r"))!==false){
				while(($item=fgetcsv($handle,10000,";"))!==false){
					print_pre($item);
				}
			}
		}
	}
}
Categories: PHP Tags:
12 февраля 2020 Нет комментариев
$curl=curl_init();
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl,CURLOPT_HEADER,0);
curl_setopt($curl,CURLOPT_POST,1);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
curl_setopt($curl,CURLOPT_PROXY,$proxy_ip);
curl_setopt($curl,CURLOPT_PROXYPORT,$proxy_port);
curl_setopt($curl,CURLOPT_PROXYAUTH,CURLAUTH_DIGEST);
curl_setopt($curl,CURLOPT_PROXYUSERPWD,$proxy_user.':'.$proxy_password);
$result=curl_exec($curl);
Categories: PHP Tags:
7 февраля 2020 Нет комментариев
header("Content-Type: application/javascript");
Categories: PHP Tags: