15 августа 2019
Нет комментариев
$item['date']
— timestamp прошедшей даты
$date_today=strtotime(date('Y-m-d',time())); $sec_diff=$date_today-$item['date']; $date_diff=floor($sec_diff/(60*60*24));
$item['date']
— timestamp прошедшей даты
$date_today=strtotime(date('Y-m-d',time())); $sec_diff=$date_today-$item['date']; $date_diff=floor($sec_diff/(60*60*24));
Создавать целевую папку, если такая не существует перед копированием. Использовать вместо функции copy
:
function copy_to_dir($from,$to){ $path=pathinfo($to); if(!file_exists($path['dirname'])){ mkdir($path['dirname'],0777,true); } if(!copy($from,$to)){ return false; } return true; }
$max
— максимальное кол-во переносов строк подряд
function remove_breaks($html,$max){ //$html=trim(preg_replace("/[\r\n|\r|\n]{".($max+1).",}/u",str_repeat("\r\n",$max),$html)); $html=trim(preg_replace("/(\r\n|\r|\n){".($max+1).",}/u",str_repeat("\r\n",$max),$html)); return($html); } $html=remove_breaks($html,1);
function remove_comments($html){ return preg_replace('/<!--(.*?)-->/','',$html); }
Использовать javascript: window.top.location.href
Например вместо:
header("Location: ".$result_data->response->body->url_login);
указать:
header("Location: /?goto=".$result_data->response->body->url_login);
и на самой странице:
<?php if(isset($_GET['goto'])){?> <script> window.top.location.href="<?=$_GET['goto']?>"; window.location.href="<?=$_GET['goto']?>"; </script> <?}?>
header('X-XSS-Protection:0');
Например, для замены в $text
{lists_4}
на название списка и список элементов:
preg_match_all("/{lists\s*(.*?)}/si",$text,$matches,PREG_SET_ORDER); if(count($matches)>0){ foreach($matches as $m){ $me=explode('_',trim(trim($m[0],'}'),"{")); if($me[0]=='lists'&&$me[1]>0){ $replace=''; $list=get_by_id($me[1],'lists'); if($list['id']){ $items=get_from_base('*','list_items',"`parent`='".$list['id']."' and `shown`=1",'pos'); if(count($items)>0){ $replace.='<div class="list">'; $replace.='<div class="name">'.$list['name'].'</div>'; $replace.='<ul>'; foreach($items as $count=>$item){ $replace.='<li class="item">'.$item['name'].'</li>'; } $replace.='</ul>'; $replace.='</div>'; } } $text=str_replace($m,$replace,$text); } } }