PHP加密解密
PHP加密和解密函数可以用来加密一些有用的字符串存放在数据库里,并且通过可逆解密字符串,该函数使用了base64和MD5加密和解密。
1 2 3 4 5 6 7 8 9 | function encryptDecrypt($key, $string, $decrypt){ if($decrypt){ $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($string), MCRYPT_MODE_CBC, md5(md5($key))), "12"); return $decrypted; }else{ $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key)))); return $encrypted; } } |
使用方法如下:
1 2 3 4 5 | //以下是将字符串“Helloweba欢迎您”分别加密和解密 //加密: echo encryptDecrypt('password', 'Helloweba欢迎您',0); //解密: echo encryptDecrypt('password', 'z0JAx4qMwcF+db5TNbp/xwdUM84snRsXvvpXuaCa4Bk=',1); |
PHP生成随机字符串
1 2 3 4 5 6 7 8 | function generateRandomString($length = 10) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, strlen($characters) - 1)]; } return $randomString; } |
PHP获取文件扩展名(后缀)
1 2 3 4 | function getExtension($filename){ $myext = substr($filename, strrpos($filename, '.')); return str_replace('.','',$myext); } |
PHP获取文件大小并格式化1
1 2 3 4 5 6 7 8 | function formatSize($size) { $sizes = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"); if ($size == 0) { return('n/a'); } else { return (round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $sizes[$i]); } } |
PHP获取文件大小并格式化2
1 2 3 4 5 | function format_bytes($size, $delimiter = '') { $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB'); for ($i = 0; $size >= 1024 && $i < 5; $i++) $size /= 1024; return round($size, 3) . $delimiter . $units[$i]; } |
PHP获取文件大小并格式化3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | function getFilesize($num){ $p = 0; $format='bytes'; if($num>0 && $num<1024){ $p = 0; return number_format($num).' '.$format; } if($num>=1024 && $num<pow(1024, 2)){ $p = 1; $format = 'KB'; } if ($num>=pow(1024, 2) && $num<pow(1024, 3)) { $p = 2; $format = 'MB'; } if ($num>=pow(1024, 3) && $num<pow(1024, 4)) { $p = 3; $format = 'GB'; } if ($num>=pow(1024, 4) && $num<pow(1024, 5)) { $p = 3; $format = 'TB'; } $num /= pow(1024, $p); return number_format($num, 3).' '.$format; } |
PHP替换标签字符
1 2 3 4 | function stringParser($string,$replacer){ $result = str_replace(array_keys($replacer), array_values($replacer),$string); return $result; } |
使用方法:
1 2 3 | $string = 'The {b}anchor text{/b} is the {b}actual word{/b} or words used {br}to describe the link {br}itself'; $replace_array = array('{b}' => '<b>','{/b}' => '</b>','{br}' => '<br />'); echo stringParser($string,$replace_array); |
PHP列出目录下的文件名
1 2 3 4 5 6 7 8 9 10 11 12 | function listDirFiles($DirPath){ if($dir = opendir($DirPath)){ while(($file = readdir($dir))!== false){ if(!is_dir($DirPath.$file)) { echo "filename: $file<br />"; } } } } listDirFiles('home/some_folder/'); |
PHP获取当前页面URL
1 2 3 4 5 6 7 8 9 10 11 12 13 | function curPageURL() { $pageURL = 'http'; if (!empty($_SERVER['HTTPS'])) {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } echo curPageURL(); |
php curl函数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | function http_curl($url){ $curl = curl_init(); $header[] = ""; $cookie=""; curl_setopt($curl,CURLOPT_URL,$url); curl_setopt($curl, CURLOPT_HTTPHEADER,$header); curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,30); curl_setopt($curl,CURLOPT_RETURNTRANSFER,1); curl_setopt($curl, CURLOPT_COOKIE, $cookie); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); //curl_setopt ($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1'); $response=curl_exec($curl); curl_close($curl); return $response; } |
PHP 返回13位时间戳
1 2 3 4 | function getMillisecond() { list($t1, $t2) = explode(' ', microtime()); return (float)sprintf('%.0f',(floatval($t1)+floatval($t2))*1000); } |
Unicode解码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 方法一: function unicode_decode($str) { //Unicode解码 linux UCS-2BE,windows UCS-2LE $t = preg_replace("#\\\u([0-9a-f]{4})#ie", "iconv('UCS-2BE', 'UTF-8', pack('H4', '\\1'))", $str); return $t; } 方法二: $content = unicode_decode($_POST['content']); echo $content ; function unicode_decode($name){ $json = '{"str":"'.$name.'"}'; $arr = json_decode($json,true); if(empty($arr)) return ''; return $arr['str']; } |
2019年6月5日 下午2:10 沙发
黑幕曝光投诉网是一个综合维护权益网站,呼吁增强群众法律意识,曝光黑心企业,揭露行业黑幕,以及各种骗子骗局。力争维护人民权益,共建和谐世界。警钟长鸣!
网址:www.qqw0.com
2019年6月9日 下午5:10 1层
@黑幕曝光维权网 额额