File search.php for phpCEDICT

<?php
// Copyright 2004 Christopher Sexton
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details: <http://www.gnu.org/licenses/gpl.txt>
 
?>
<?php require_once('include/config.php'); ?>
<?php require_once('include/util.php'); ?>
<html>
<head>
<title>CEDICT</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="chinese.css" rel="stylesheet" type="text/css">
</head>
 
<body>
<div id="main">
  <div align="right">
  <form action="search.php" method="get" name="Search" target="_self">  
  <input name="query" type="text" value="<?   if (isset($_GET['query'])){$query = $_GET['query']; }?><?=$query?>">
  <input name="search" value="English" type="Submit">
  <input name="search" value="Pinyin" type="Submit">
  <input name="search" value="Chinese" type="Submit">
  </div>
  </form>
 
<?php  
//Init the varables
$start = 0;
$count = 0;
if (isset($_GET['start'])) {$start = $_GET['start'];}
if (isset($_GET['search'])) {$search = $_GET['search'];} else { $search = "English";}
 
// process form  
if (isset($_GET['query'])) 
{
     $query = $_GET['query'];
	 
	 //$query = str_replace(";"," ",$query);
	 //$query = str_replace("&#","",$query);
 	if ( $search == "English" )	$sql = "SELECT * FROM cedict WHERE english like '%$query%' LIMIT $start,10;";
 	if ( $search == "Pinyin" )	$sql = "SELECT * FROM cedict WHERE pinyin like '%$query%' LIMIT $start,10;";
 	if ( $search == "Chinese" ){
		$chinesequery = strip_entities($query);
		$sql = "SELECT * FROM cedict WHERE simplified like '%$chinesequery%' OR traditional like '%$chinesequery%'LIMIT $start,10;";
	} // $search == "Chinese" 
 
	//echo $sql;
  	$result = mysql_query($sql);
	print ( "<center><i>Searching $search for '$query'</i></center><br>");
	
	if (mysql_num_rows($result) > 0)
	{
	?>
	<table width="80%"  border="0" align="center" cellspacing="3" class="chinese_table">
          <tr class="chinese_header">
            <td>Simplified [Traditional]</td>
            <td>Pinyin</td>
            <td>English</td>
          </tr>	
	<?	
	while ($myrow = mysql_fetch_row($result)) 
	{
		$count = $count + 1 ;
		?>
		  <tr align="left" valign="top">
            <td><?=printChineseWithUnihanLink(unicode_to_entities(db_to_unicode($myrow[2])))?>
			[<?=printChineseWithUnihanLink(unicode_to_entities(db_to_unicode($myrow[1])))?>]
			</td>
            <td class="chinese_content"><?=pinyin_to_unicode($myrow[3])?></td>
            <td class="chinese_content"><?=str_replace("/","<br />",trim($myrow[4],"/"));?></td>
      </tr>
		<?php
	} //while ($myrow = mysql_fetch_row($result)) 
  }//if (mysql_num_rows($result) > 0)
  else
  {
    echo "<center><b><i>No results found.  That's too bad.</i></b></center>";
  }
  if ($count == 10){
	$start = $start + 10;
	echo ("<tr align='left'  class='chinese_content'>
            <td>[<a href='search.php?query=". urlencode($query) ."&start=$start'>MORE</a>]</td>
			<td></td><td></td></tr>");
  }
  ?>
  </table>
  <?
 
} // if (isset($_GET['query']))
else
{
?>
  <h3>phpCEDICT</h3>
  <p class="chinese_content">This is a php and MySQL implemtation of <a href="http://www.mandarintools.com/cedict.html">CEDICT</a>. CEDICT is a downloadable public-domain Chinese-English dictionary. This page takes advantage of CEDICT by importing the file into a database for faster and easier searching. <a href="http://www.fuzzymonk.com/wiki/?pagename=Code.Cedict">phpCEDICT</a> is an open source (read: GPL'd) project. </p>
  <h3>Search Tips</h3>
  <span class="chinese_content">
  <ul>
    <li>To add a wild card use the percent (%) sign. </li>
  </ul>
  English
  <ul>
    <li>English is the default, so if you want to search for english just press enter.</li>
    <li>To search for a whole word put /'s around the word. Ex: /word/ </li>
  </ul>
  Pinyin
  <ul>
    <li>To search for tones, add the tone on the end of the word. Ex: bi2 gong1 xiang2</li>
    <li>Do not use a 5 for a fith tone, leave it blank. </li>
    <li>To search for a ü use a 'u' followed by a ':'. Ex: nu:3 </li>
  </ul>
  Chinese
  <ul>
    <li>Chinese expects the input to be in UTF-8 encoding, it should be handled by the browser.</li>
    <li>For details on the MSIME see <a href="http://www.fuzzymonk.com/wiki/?pagename=Chinese.InstallingIMEOnWindows">InstallingIMEOnWindows</a>.</li>
  </ul>
  </span>     
<?
} //else if(isset($_GET['query']))
?>
</div>
<div class="copyright" align="center">&copy; 2004 <a href="http://www.fuzzymonk.com">Chrisopher Sexton</a></div>
</body>
</html>
 
  code/cedictsearch.txt · Last modified: 2005/01/06 11:34
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki