$timeout=15; curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); curl_setopt($ch,CURLOPT_TIMEOUT,$timeout);
Архив
Нужно используя CURL просто получить URL перенаправления, но не переходить по нему внутри CURL.
$post_fields=array( "field1"=>$value1, "field2"=>$value2, ); $curl=curl_init(); curl_setopt($curl,CURLOPT_URL,'https://site.ru/path/'); curl_setopt($curl,CURLOPT_HEADER,1); curl_setopt($curl,CURLOPT_POST,1); curl_setopt($curl,CURLOPT_RETURNTRANSFER,1); curl_setopt($curl,CURLOPT_FOLLOWLOCATION,false); curl_setopt($curl,CURLOPT_POSTFIELDS,$post_fields); $res=curl_exec($curl); curl_close($curl); preg_match_all('/^Location:(.*)$/mi',$res,$matches); if(!empty($matches[1])){ header("Location: ".trim($matches[1][0]),true,301); } exit();
При отправке писем, используя функцию php mail(), при появлении в сообщении в произвольных на первый взгляд местах символов "! " (восклицательный знак и пробел) — вручную добавить переносы строк:
$crlf="\r\n"; $message.='...text'.$crlf;
Проблема из-за ограничения длины строки (вероятно возможно где-то увеличить этот лимит, но надежнее добавить переносы строк, чтобы избежать проблем при переносе сайта на другой сервер с default настройками).
Используются плагины: AMP for WP — Accelerated Mobile Pages for WordPress, WP-GeSHi-Highlight.
Синтаксис внутри pre подсвечиваться конечно не будет.
В файл functions.php активной темы:
</pre > заменить на </pre> т.е. без пробела
function echapcode($a){ return "<pre $a[1]>".htmlspecialchars($a[2])."</pre >"; } $texte=preg_replace_callback('#<pre (.*?)>(.*?)</pre >#ius','echapcode',$text); add_filter('the_content','new_pre_content'); function new_pre_content($content){ if(function_exists('ampforwp_is_amp_endpoint')&&forwp_is_amp_endpoint()){ $content=preg_replace_callback('#<pre (.*?)>(.*?)</pre >#ius','echapcode',$content); } return $content; }
Форматирование телефонов, указанных в произвольном формате.
Например, для преобразования телефона в ссылку tel:
function href_tel($phone,$text=''){ if(!$text){ $text=$phone; } $d=preg_replace('~\D+~','',$phone); if(strlen($d)>=10){ return '<a href="tel:+7'.substr($d,-10,10).'">'.$text.'</a>'; } else{ return $phone; } }
Преобразование к формату +7 (999) 123-45-67:
function phone_format($phone){ $d=substr(preg_replace('~\D+~','',$phone),-10,10); if(strlen($d)>=10){ return "+7 (".substr($d,0,3).") ".substr($d,3,3)."-".substr($d,6,2)."-".substr($d,8,2); } else{ return $phone; } }
Для открытия в браузере:
header("Content-type:application/pdf"); header("Content-Disposition:inline;filename='agreement.pdf'");
Для скачивания:
header("Content-type:application/pdf"); header("Content-Disposition:attachment;filename='agreement.pdf'");
При формировании XML:
$text=preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u',' ',$text);
Полная функция:
function prepare_to_xml($text){ $text=preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u',' ',$text); $text=strip_tags($text); $text=htmlspecialchars($text); $text=str_replace("\t"," ",$text); $text=str_replace("&nbsp;"," ",$text); $text=str_replace(" "," ",$text); $text=preg_replace("/[\r\n]+/i","",$text); $text=preg_replace('/ {2,}/',' ',$text); $text=trim($text); return $text; }
Ну или просто:
function utf8_for_xml($string){ return preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u',' ',$string); }