<?php
$source = <<<'code'
<?php
$name = 'anon';
echo '<h2>';
echo 'Number is: ';
echo count(["1","2","3"]);
echo '</h2>';
echo 'CHECK
';
echo 1 + 3 . '-'. 4 . '=' . 0;
echo '
';
echo '<h2>';
echo 'Olololo';
echo '</h2>';
echo '
';
echo '<h3>';
echo 'QWErty';
echo '</h3>';
echo '
';
echo '<h2>';
echo 'Hello, ';
echo $name;
echo '</h2>';
echo '
';
foreach ([1,2,3] as $item) {
echo '
';
echo '<h2>';
echo 'Number is: ';
echo $item;
echo '</h2>';
echo '
';
}
code;
$tokens = token_get_all($source);
$last_token=false;
$getnext=function() use (&$tokens, &$last_token){
$token=array_shift($tokens);
if(is_null($token)) return false;
if(is_array($token)){
$last_token= token_name($token[0]);
return $token[1];
} else {
$last_token='';
return $token;
}
};
$getbracket=function($bracket) use (&$tokens,$getnext,&$last_token){
$stack=[]; $buf=$bracket;
if($bracket=='[') array_unshift($stack,']');
if($bracket=='(') array_unshift($stack,')');
while(false!==($x=$getnext())){
$buf.=$x;
if($x==$stack[0]){
array_shift($stack);
if(count($stack)==0) break;
}
if($x=='(') array_unshift($stack,')');
if($x=='{') array_unshift($stack,'}');
if($x=='[') array_unshift($stack,']');
}
return $buf;
};
$getecho=function() use (&$tokens,$getnext,$getbracket,&$last_token){
$buf='';
$buf2='';
$waitecho=false;
while(false!==($x=$getnext())){
//echo '{'.$last_token.' '.$x.'}';
if($last_token==='' && $x==';'){
$waitecho=true;
$buf2.=$x;
} elseif($last_token==='T_ECHO' && $waitecho){ // склеиваем
$waitecho=false;
$buf.=',';$buf2='';
} elseif($last_token==='T_WHITESPACE' && $waitecho){
$buf2.=$x;
} else if($waitecho){
return $buf.$buf2.$x;
} else if($last_token==='T_CONSTANT_ENCAPSED_STRING') {// склеиваем константные строки с одинаковыми кавычками
$s=$x[0];
$y = preg_replace('~'.preg_quote($s,"~'").'\s*[\.\,]\s*$~', '', $buf, 1, $count);
if($count>0)
$buf=$y.substr($x,1);
else
$buf.=$x;
} else if($last_token==='' && in_array($x,['[','('])) {
$buf.=$getbracket($x);
} else {
$buf.=$x;
}
};
return '';
};
while(false!==($x=$getnext())) {
echo $x;
if($last_token=='T_ECHO'){
echo $getecho();
}
}
?>
<?php
$name = 'anon';
echo '<h2>Number is: ', count(["1","2","3"]), '</h2>CHECK
', 1 + 3 . '-'. 4 . '=' . 0, '
<h2>Olololo</h2>
<h3>QWErty</h3>
<h2>Hello, ', $name, '</h2>
';
foreach ([1,2,3] as $item) {
echo '
<h2>Number is: ', $item, '</h2>
';
}
const rect = $canvas.getBoundingClientRect(); // после этого вставить 2 строки
$($canvas).attr('width', rect.width);
$($canvas).attr('height', rect.height);
//...
<?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'));
days.toString().replace(/\d/gi, (substring) => `${substring}`);
daysVal.innerHTML = '<span>'+days.toString().padStart(2,'0')+'</span>';
hoursVal.innerHTML = '<span>'+hours.toString().padStart(2,'0')+'</span>';
minutesVal.innerHTML = '<span>'+minutes.toString().padStart(2,'0')+'</span>';
<?php die("Access Denied"); ?>#x#a:2:{s:6:"result";a:227:{i:0;O:8:"stdClass":8:{s:2:"id";s:3:"870";s:5:"title";s:23:"БПВР-вопросы";s:6:"module";s:13:"mod_widgetkit";
$(function() {
var valMap = [0, 1, 3, 6, 10, 15, 22, 30,40, 50]; // более равномерно в логарифмической шкале
// 0..1000 --> 0..50 (true, обратно false)
const step=2,
w=[1000/Math.pow(50,1/step),50/Math.pow(1000,step)] ;
function _conv(x, forvard){
if(!forvard)
return Math.pow(x,1/step)*w[0];
else
return Math.round(Math.pow(x,step)*w[1]);
}
$("#slider").slider({
max: 1000,//valMap.length - 1,
slide: function(event, ui) {
$("#radiusAmount").val(_conv(ui.value,true));
}
})
.each(function() {
var opt = $(this).data().uiSlider.options;
var vals = opt.max - opt.min;
var arrayLength = valMap.length;
for (var i = 0; i < arrayLength; i++) {
var el = $('<label>' + (valMap[i]) + '</label>').css('left', (_conv(valMap[i],false) / 10 ) + '%');
$("#slider").append(el);
}
});
$(document).on('change','#radiusAmount', function(){
$("#slider").slider('value',_conv($(this).val(), false)) ; })
});