日期:2014-05-17 浏览次数:20609 次
<?php $title = '新华字典'; //查询名称,不必修改 $is_cache = 1; //缓存设置 1打开 0关闭 $dbhost = xxx.com'; //MYSQL服务器【需配置】 $dbname = 'acz'; //数据库名称【需配置】 $dbuser = 'acz'; //数据库用户名【需配置】 $dbpw = 'FKXwBDu'; //数据库密码【需配置】 $tbname = 'zi'; //数据表名【需配置】 function getlink($query){ global $dbhost,$dbuser,$dbpw,$dbname; $link = mysql_connect($dbhost, $dbuser, $dbpw) or die('无法连接: ' . mysql_error()); mysql_query("set character set 'utf8'"); mysql_select_db($dbname) or die('不能连接数据库!'); mysql_query("SET NAMES UTF8"); // 执行 SQL 查询 $result = mysql_query($query) or die('查询失败: ' . mysql_error()); return $result; } $bpa = "丨亅丿乛一乙乚丶八勹匕冫卜厂刀刂儿二匚阝丷几卩冂力冖凵人亻入十厶亠匸讠廴又艹屮彳巛川辶寸大飞干工弓廾广己彐彑巾口马门宀女犭山彡尸饣士扌氵纟巳土囗兀夕小忄幺弋尢夂子贝比灬长车歹斗厄方风父戈卝户火旡见斤耂毛木肀牛牜爿片攴攵气欠犬日氏礻手殳水瓦尣王韦文毋心牙爻曰月爫支止爪白癶歺甘瓜禾钅立龙矛皿母目疒鸟皮生石矢示罒田玄穴疋业衤用玉耒艸臣虫而耳缶艮虍臼米齐肉色舌覀页先行血羊聿至舟衣竹自羽糸糹貝采镸車辰赤辵豆谷見角克里卤麦身豕辛言邑酉豸走足青靑雨齿長非阜金釒隶門靣飠鱼隹風革骨鬼韭面首韋香頁音髟鬯鬥高鬲馬黄鹵鹿麻麥鳥魚鼎黑黽黍黹鼓鼠鼻齊齒龍龠"; //部首数组 if($_POST['q']){ //搜索 $q = htmlspecialchars(trim($_POST['q'])); }elseif($_GET['id']){ $id = $_GET['id']; //$id = intval(base64_decode($_GET['id'])); }elseif($_GET['list']){ $lst = intval($_GET['list']); } function getR($q){ //搜索 global $bpa,$tbname; if(preg_match("/^[A-Za-z]+$/",$q)){ //如果搜的拼音 $sql = "select id,zi from ".$tbname." where py = '".strtolower($q)."' limit 150"; }else{ $sql = "select id,zi from ".$tbname." where zi like '%".$q."%' limit 150"; } $result = getlink($sql); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { $res[] = $line; } if(count($res)==1) header("location: ?id=".$res[0]['id']); return $res; } function getArr($num,$t=0){ //获取缓存的数据 if($t==0){ $furl = "cache\\".floor(($num-1)/1000)."\\"; }else{ $furl = 'cache\\'; } $filename = $furl.$num.".txt"; //缓存文件名 if(file_exists($filename)){ return unserialize(@file_get_contents($filename)); }else{ return false; } } function cacheArr($num,$arr,$t=0){ //将数据存下来 if($t==0){ $furl = "cache\\".floor(($num-1)/1000)."\\"; }else{ $furl = 'cache\\'; } $filename = $furl.$num.".txt"; //缓存文件名 if(!file_exists($furl)){ //创建文件夹 if(!file_exists("cache\\") && $t==0){ mkdir("cache\\", 0777); } mkdir($furl, 0777); } $t=serialize($arr); $fp = @fopen($filename,"w"); @fwrite($fp,$t); @fclose($fp); } function listzidian($id){ //列表 global $bpa,$tbname,$is_cache; if($is_cache==1){ $c = getArr($id,1); if($c!=false) return $c; } $pos = substr($bpa,$id*3-3,3); if($pos==""){ $sql = "select id,zi,bihua from ".$tbname." where bushou='难检字' or bushou='' order by bushou"; $res['type'] = "难检字"; }else{ $sql = "select id,zi,bihua from ".$tbname." where bushou='".$pos."' order by bushou"; $res['type'] = $pos; } $result = getlink($sql); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { $res[] = $line; } if($is_cache==1){ cacheArr($id,$res,1); } return $res; } function zidian($id){ //某个ID global $is_cache,$tbname; if($is_cache==1){ $c = getArr($id); if($c!=false) return $c; } $sql = "select * from ".$tbname." where id=".$id." limit 1"; $result = getlink($sql); $line = mysql_fetch_array($result