Архив

Публикации с меткой ‘PHP’
11 марта 2021 Нет комментариев

Для латиницы функция ucfirst
Для utf-8:

function ucfirst_utf8($str){
	return mb_strtoupper(mb_substr($str,0,1)).mb_substr($str,1);
}
echo ucfirst_utf8("предложение с большой буквы");
Categories: PHP Tags:
16 февраля 2021 Нет комментариев
$result=array_diff($all_files,$current_files);
Categories: PHP Tags:
25 августа 2020 Нет комментариев
$zip=new ZipArchive;
$zip->open(ROOT_DIR.IMPORT_DIR.'import.zip');
for($i=0;$i<$zip->numFiles;$i++){
	$stat=$zip->statIndex($i);
	$import_file=basename($stat['name']);
	echo $import_file."\r\n";
}
$zip->extractTo(ROOT_DIR.IMPORT_DIR);
$zip->close();
Categories: PHP Tags:
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:
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: