1.去除字符串中的全部空格,包括全角中文空格
php
$key =preg_replace("/\s| /","",$key);
2.正則提取
html
$contents="var hintWordArr =1234567;"; preg_match_all("|var hintWordArr =(.*?);|U",$contents,$xgArr); print_r($xgArr);
3.字符串加密與解密
緩存
//http://tu.139zhuti.com/show3.php?p= $t = 'http://img.bzcm.net/news/attachement/jpg/site2/20131202/842b2b97e020140610f901.JPG'; $k = '125896348'; function passport_encrypt($txt, $key) { srand((double)microtime() * 1000000); $encrypt_key = md5(rand(0, 32000)); $ctr = 0; $tmp = ''; for($i = 0;$i < strlen($txt); $i++) { $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr; $tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]); } return base64_encode(passport_key($tmp, $key)); } function passport_decrypt($txt, $key) { $txt = passport_key(base64_decode($txt), $key); $tmp = ''; for($i = 0;$i < strlen($txt); $i++) { $md5 = $txt[$i]; $tmp .= $txt[++$i] ^ $md5; } return $tmp; } function passport_key($txt, $encrypt_key) { $encrypt_key = md5($encrypt_key); $ctr = 0; $tmp = ''; for($i = 0; $i < strlen($txt); $i++) { $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr; $tmp .= $txt[$i] ^ $encrypt_key[$ctr++]; } return $tmp; } $e = passport_encrypt($t,$k); $e = 'VzoHegkmB3BQPgYrUy9QPgVqVDIBJgI2BmNWfgNnVzoHbwQiAC4CdQU9Uj9UZgRnUXwBaQNnAmFQZVMwUSVRfFdgBz4JYwczUCsGNVMyUHgFN1RhAScCMQZnVmgDMldkBzMEOgBtAjIFaVIPVDUEMlFnATADPwI1UDJTZlFvUWZXfAdkCSIHZw=='; echo $e; echo "<br>"; echo passport_decrypt($e,$k);
4.CURL的POST
curl
class HttpUtil { public static function post($url, $data) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $tmpInfo = curl_exec($ch); if (curl_errno($ch)) { return false; } curl_close($ch); return $tmpInfo; } }
5.字符編碼轉換
post
$str=mb_convert_encoding($str, "utf-8", "gbk");//將原來是gbk的字符轉換成utf-8
6.生成本地緩存
編碼
ob_start(); //print_r($data); $datastr = ob_get_contents(); ob_clean(); file_put_contents("/home/wwwroot/html/test.html",$datastr);