天天看點

查漢字拼音查漢字拼音

查漢字拼音

拼音檔案見:http://www.eguidedog.net/zhspeak.php

運作結果:

查漢字拼音查漢字拼音

代碼:

<?php
#preg_grep();
#explode(".",$str);
#str_split("Hello");
#strcmp("Hello world!","Hello world!");
#strpos("I love php, I love php too!","php");
#file(path,include_path,context) ;
#file("test.txt");
#print_r(explode("."," 哈.哈.啊"));
#chunk_split($str,1,"."); echo chunk_split("哈哈啥",3,"。");

$shuchu=false;//不帶引号,bool,帶引号,就是指派了,會出錯。
if (!empty($_REQUEST["chaxun"]) ) {
$chaxun =  htmlspecialchars($_POST["chaxun"]);
//除去空格
$chaxun = str_replace(" ","",$chaxun);
/*//除去前後空格. 
$chaxun=chop($chaxun);
$chaxun=strrev($chaxun);
$chaxun=chop($chaxun);
$chaxun=strrev($chaxun);
*/
$chaxun = explode( "+",chunk_split($chaxun,3,"+") );//待查詢漢字數組
#echo "查詢漢字為:";print_r($chaxun);
$hzdb = file("zh_listx");//資料庫數組
#echo "資料庫為:";print_r($hzdb);
$hzdblength=count($hzdb);# echo "資料庫總數".$hzdblength;
$chaxunlength=count($chaxun);
$chaxunlength=$chaxunlength-1;# echo "查詢總數".$chaxunlength;
/*for($y=0;$y<$chaxunlength;$y++){ 
for($x=0;$x<$hzdblength;$x++)
{
	if( strpos($hzdb[$x],$chaxun[$y]) ){    
		echo $hzdb[$x]; #echo $x.$y;
		echo "<br>";
	} #echo $x."<br/>";
}
}*/ #在html中輸出,便于控制。
$shuchu=true;
}
?>

<!DOCTYPE html>
<html >

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>查拼音</title>
</head>

<body ><a name="top"> </a>
<form method="post" action="">
<input type="text" name="chaxun" value="" placeholder="輸入漢字查拼音。"><br>
<input type="submit" value="查詢">
</form>
<!--
<table><thead>
<tr><th>  </th></tr>
</thead><tbody> -->
<?php 
if ($shuchu){
	#echo "<td>有查詢 </td>";
$table1="
<table><thead>
<tr><th>
";
$table2="
</th></tr>
</thead><tbody>
";
$table3="
</tbody></table>
";
//連結
for($y=0;$y<$chaxunlength;$y++){ 
echo "<a name=\"chaxun\" href=\"#$chaxun[$y]\">$chaxun[$y] &nbsp;</a>";
}
//結果
for($y=0;$y<$chaxunlength;$y++){ 
echo $table1."<a href=\"#chaxun\" name=\"$chaxun[$y]\" >$chaxun[$y]</a>".$table2;
for($x=0;$x<$hzdblength;$x++)
{
	if( strpos($hzdb[$x],$chaxun[$y]) ){    
		#$hzdb[$x]=rtrim($hzdb[$x],"\n");	# 帶有換行符。	
		echo "<tr><td>$hzdb[$x]</td></tr>"; #echo $x.$y;
		
	} #echo $x."<br/>";
}echo $table3;
}
}
?>
<!--</tbody></table>-->
<a href="#top" target="_blank" rel="external nofollow" > 頂部</a>
<br/><br/><br/><br/><br/>
</body>
</html>