function password_strength($string){
$h = 0;
$size = strlen($string);
foreach(count_chars($string, 1) as $v){
$p = $v / $size;
$h -= $p * log($p) / log(2);
}
$strength = ($h / 4) * 100;
if($strength > 100){
$strength = 100;
}
return $strength;
}
var_dump(password_strength("Correct Horse Battery Staple"));
echo "<br>";
var_dump(password_strength("Super Monkey Ball"));
echo "<br>";
var_dump(password_strength("Tr0ub4dor&3"));
echo "<br>";
var_dump(password_strength("abc123"));
echo "<br>";
var_dump(password_strength("sweet"));
15.检测浏览器语言,只提供可用的$availableLanguages作为数组(‘en', ‘de', ‘es')
复制代码 代码如下:
function get_client_language($availableLanguages, $default='en'){
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$langs=explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
//start going through each one
foreach ($langs as $value){
$choice=substr($value,0,2);
if(in_array($choice, $availableLanguages)){
return $choice;
}
}
}
return $default;
}
16.创建数据URL
复制代码 代码如下:
function data_uri($file, $mime) {
$contents=file_get_contents($file);
$base64=base64_encode($contents);
echo "data:$mime;base64,$base64";
}
17.创建更加友好的页面标题SEO URL
输入示例:$title = “This foo's bar is rockin' cool!”; echo makeseoname($title); //RETURNS: //this-foos-bar-is-rockin-cool
复制代码 代码如下:
function make_seo_name($title) {
return preg_replace('/[^a-z0-9_-]/i', '', strtolower(str_replace(' ', '-', trim($title))));
}
18.终极加密功能
复制代码 代码如下:
// f(ucking) u(ncrackable) e(ncryption) function by BlackHatDBL ()
function fue($hash,$times) {
// Execute the encryption(s) as many times as the user wants
for($i=$times;$i>0;$i--) {
// Encode with base64...
$hash=base64_encode($hash);
// and md5...
$hash=md5($hash);
// sha1...
$hash=sha1($hash);
// sha256... (one more)
$hash=hash("sha256", $hash);
// sha512
$hash=hash("sha512", $hash);
}
// Finaly, when done, return the value
return $hash;
}
19a.Tweeter Feed Runner——使用任意twitter名,可在任意页面上加载用户资源。
复制代码 代码如下: