3 февраля 2016
Нет комментариев
function str_replace_once($search,$replace,$text){ $pos=strpos($text,$search); return $pos!==false?substr_replace($text,$replace,$pos,strlen($search)):$text; }
function str_replace_once($search,$replace,$text){ $pos=strpos($text,$search); return $pos!==false?substr_replace($text,$replace,$pos,strlen($search)):$text; }
Регистронезависимый поиск по вхождению строки на русском в utf-8 (необходимо указание кодировки)
if(mb_stristr($data_vid_naness_text,'тиснение',false,'utf-8')){ }
Усовершенствованное решение этого варианта: http://krylov.org.ua/?p=1130
.htaccess
RewriteCond %{REQUEST_URI} ^(.*)/{2,}(.*)$ RewriteRule . %1/%2 [R=301,L]
Работает для http://site.com/dir1///dir2
но проблема остается в адресах типа http://site.com///uri (несколько слешей после домена)
Решение на php:
if(stristr($_SERVER['REQUEST_URI'],'//')){ $uri=preg_replace('#/{2,}#','/',$_SERVER['REQUEST_URI']); header('Location: '.$uri,false,301); exit; }
В примере необходимо генерировать в URL фильтрацию по цене только в том случае, если пользователь сам изменил ползунок выбора цены.
Т.е. нужно не передавать определенные параметры в _GET (по ситуации).
Часть формы (добавляем hidden поля):
<form method="get" action="" id="filter_form"> от <input type="text" name="price_from" id="price_from" value="100"/> до <input type="text" name="price_to" id="price_to" value="1000"/> <input type="hidden" id="price_min" value="100"/> <input type="hidden" id="price_max" value="1000"/> </form>
Яваскриптом дисаблим inputы, если их значения не меняли.
$(function(){ $("#filter_form").submit(function(){ if($("#price_from").val()==$("#price_min").val()){ $("#price_from").attr("disabled","disabled"); } if($("#price_to").val()==$("#price_max").val()){ $("#price_to").attr("disabled","disabled"); } }); });
function find_emails($text){ $emails=array(); preg_match_all('/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6})/',$text,$potential_emails,PREG_SET_ORDER); for($i=0;$i<count($potential_emails);$i++){ $potential_email=$potential_emails[$i][0]; if (filter_var($potential_email,FILTER_VALIDATE_EMAIL)){ if (!in_array($potential_email,$emails)){ $emails[]=$potential_email; } } } return $emails; }
function htmlizeEmails($text){ preg_match_all('/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6})/',$text,$potentialEmails,PREG_SET_ORDER); $potentialEmailsCount=count($potentialEmails); for($i=0;$i<$potentialEmailsCount;$i++){ if(filter_var($potentialEmails[$i][0],FILTER_VALIDATE_EMAIL)){ $text=str_replace($potentialEmails[$i][0],'<a href="mailto:'.$potentialEmails[$i][0].'">'.$potentialEmails[$i][0].'</a>',$text); } } }
Использование:
$str="Send me an email to [email protected]."; echo htmlizeEmails($str); //Echoes "Send me an email to <a href="mailto:[email protected]">[email protected]</a>."
http://stackoverflow.com/questions/9763606/detecting-emails-in-a-text
$LastModified_unix=1234567890;//time() $LastModified=gmdate("D, d M Y H:i:s \G\M\T",$LastModified_unix); $IfModifiedSince=false; if(isset($_ENV['HTTP_IF_MODIFIED_SINCE'])){ $IfModifiedSince=strtotime(substr($_ENV['HTTP_IF_MODIFIED_SINCE'],5)); } if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){ $IfModifiedSince=strtotime(substr($_SERVER['HTTP_IF_MODIFIED_SINCE'],5)); } if($IfModifiedSince&&$IfModifiedSince>=$LastModified_unix){ header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified'); exit; } header('Last-Modified: '.$LastModified);