在kamal的建议下,整理了博客中用到的一些DEMO页:
工具类:
游戏类:
将以下PHP代码,丢入DEMO根目录即可自动生成列表:
<!doctype html> <title>叶落花开:DEMO列表</title> <style> body{line-height:1.8;font-size:14px;} .xxxxx{color:#666;font-size:12px;} </style> <h1>叶落花开:DEMO列表</h1> <ul> <?php //是否为UTF8编码 function is_utf8 ( $string ) { // From http://w3.org/International/questions/qa-forms-utf-8.html return preg_match ( '%^(?: [\x09\x0A\x0D\x20-\x7E] # ASCII | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 )*$%xs' , $string ); } function showDemo( $filedir ) { //打开目录 $dir = dir($filedir); //列出目录中的文件 while (($file = $dir->read())!==false){ //列出除首页以外的其他文件 if(is_file($file) && $file !== 'index.php'){ //只列html和php后缀的 if(pathinfo($file, PATHINFO_EXTENSION) == 'php' || pathinfo($file, PATHINFO_EXTENSION) == 'html'){ preg_match("/<title>(.+)<\/title>/i", file_get_descriptions($file), $matches); $metaTags = get_meta_tags($file); $xxxxx = array_key_exists('xxxxx',$metaTags) ? (is_utf8($metaTags['xxxxx']) ? $metaTags['xxxxx'] : iconv("GBK", "UTF-8", $metaTags['xxxxx']) ) : $file ; //只列包含有title的DEMO if(count($matches)){ //有些DEMO是GBK的,转码一下 $title = (is_utf8($matches[1]) ? $matches[1] : iconv("GBK", "UTF-8", $matches[1])); //查询关键词 if(!empty($_GET["q"]) && (stripos($title, $_GET["q"]) === FALSE)){ continue; } echo "<li><a href=". $file .">". $title ."</a> | <span class='xxxxx'>". $xxxxx ."</span></li>"; } } } } $dir->close(); } showDemo("."); ?> </ul>