1.去除字符串中的所有空格,包括全角中文空格
$key =preg_replace("/\s| /","",$key);
2.正则提取
$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 "";echo passport_decrypt($e,$k);
4.CURL的POST
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.字符编码转换
$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);