<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authentification required.';
exit;
} else {
// config!
$password='test';
$user='test';
$upload_dir=$_SERVER['DOCUMENT_ROOT'].'/tmp/';
//
if($_SERVER['PHP_AUTH_USER']!=$user ||$_SERVER['PHP_AUTH_USER']!=$password){
echo 'No user found, sorry.';
exit;
}
$filename=$_SERVER['QUERY_STRING'];
if(!is_readable($upload_dir.$filename)){
echo 'No file found, sorry.';
exit;
}
header('Content-type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($upload_dir.$filename));
readfile($upload_dir.$filename);
}
count=2,<2;count=3,<300,>44
$current=45; // значение, которое сравниваем
$data=['count'=>3]; // внешние данные
if( ($data['count']==2 && $current<2) || ($data['count']==3 &&$current>44 && $current<300)){
// ...
}
function evaluate($current,$cond,$data=[]){
$res=false;
foreach(explode(';',$cond) as $or){ //or
foreach(explode(',',$or) as $and) { //and
if(preg_match('/^(.*?)(<=|>=|<|>|=)(.*?)$/',$and,$m)){
$a=trim($m[1]);$b=trim($m[3]);
if(empty($a)) $a=$current;
else if(is_numeric($a)) $a=0+$a;
else if(isset($data[$a])) $a=$data[$a];
else {
$res=false; break;
}
if(empty($b)) $b=$current;
else if(is_numeric($b)) $b=0+$b;
else if(isset($data[$b])) $b=$data[$b];
else {
$res=false; break;
}
if($m[2]=='<=') $res=$a<=$b;
else if($m[2]=='>=') $res=$a>=$b;
else if($m[2]=='>') $res=$a>$b;
else if($m[2]=='<') $res=$a<$b;
else if($m[2]=='=') $res=$a==$b;
} else {
$res=false;
//throw new \Exception('Некорректное условие в строке '.$and)
}
if(!$res) break; // выход по AND
}
if($res) break; // выход по OR
}
return $res;
}
$data=['count'=>3];
var_dump(true===evaluate(45,'count=2,<2;count=3,<300,>44', $data));
var_dump(true===evaluate(1,'<2'));
var_dump(true===evaluate(1,'>3;<2,>1;<2'));
$results_file='results.php';
$result=include_once($results_file);
$result[$current_user_id]=['post'=>$_POST, 'time'=>time()];
file_put_contents($results_file, '<'."?php\nreturn ".var_export($result,true).';')
<?php
return [];
if (preg_match('/\.gz$/', $name)) {
$_handle = fopen($name, "rb");
fseek($_handle, filesize($name) - 4);
$x = unpack("L", fread($_handle, 4));
$this->finish = $x[1];
fclose($_handle);
$handle = gzopen(
$handle, 'r'
);
} else {
$this->finish = filesize($name);
$handle = fopen($name, 'r');
}
$text=preg_replace('~\[CODE\](.*?)\[/CODE\]~si', '<pre>$1</pre>',$text);
$query=[];
parse_str(parse_url($query_string, PHP_URL_QUERY),$query_array);
unset($query_array['select']);
echo (!empty($query_array)?'?':'').http_build_query($query_array);
function getcontents($url){
if(filter_var($url,FILTER_VALIDATE_URL)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
// ssl?
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
return file_get_contents($url);
}
echo getcontents('https://www.rusprofile.ru/id/11597949');
$text = 'JA Ja jA ja';
$text = preg_replace('/J(?i:a)/', 'Я', $text);
$text = preg_replace('/j(?i:a)/', 'я', $text);
curl_setopt($ch, CURLOPT_ENCODING ,"gzip")
str_replace(
array('january','february','march','april','may','june','july',
'august','september','october','november','december'),
array('января','февраля','марта','апреля','мая','июня','июля',
'августа','сентября','октября','ноября','декабря'),
strtolower(date('j F, Y г.',
$daystr)));
и локаль аглицкая, конечно...$words=['яблоко', 'банан', 'киви', 'апельсин'];
$min_words=1;
$max_words=3;
for($i=0;$i<2**count($words);$i++){
$bin=str_pad(base_convert($i,10,2),count($words), "0", STR_PAD_LEFT);
$numword=substr_count($bin,'1');
if($numword<$min_words || $numword>$max_words)
continue;
$result=[];
for($j=0;$j<strlen($bin);$j++){
if($bin{$j}=='1') $result[]=$words[$j];
}
echo '>',implode(' ', $result), "<br>\n";
}
>апельсин
>киви
>киви апельсин
>банан
>банан апельсин
>банан киви
>банан киви апельсин
>яблоко
>яблоко апельсин
>яблоко киви
>яблоко киви апельсин
>яблоко банан
>яблоко банан апельсин
>яблоко банан киви
$re = '/((?:[-\s\(\)]*\d){9,})/m';
$str = 'D-24986 Satrup Tel. (0 46 33) 9 645 00 Fax (0 46 33) 9 66 000
Problemen: Tel. 03682-4654000,';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
$vars=[
'var1'=>100,
'var3'=>2
];
echo execute('{var1}/{var3}', $vars);
function execute($expr,$vars){
$functionname='_'.md5($expr);
if(!function_exists($functionname)){
$filename=$functionname.'.tmp.php';
if(!file_exists($filename)) {
$php_expr = preg_replace_callback('/{(.*?)}/', function ($m) use ($vars) {
if (isset($vars[$m[1]]))
return '$' . $m[1];
else
return $m[0];
}, $expr);
file_put_contents($functionname . '.tmp.php', sprintf('<' . '?php
function %s($vars){
extract($vars);
return %s;
}
', $functionname, $php_expr));
}
include_once($functionname.'.tmp.php');
}
return $functionname($vars);
}
preg_replace("/href=\"".preg_quote($url,'/')."\"/i", "href=\"$base/$url\"", $html);