http://www.b-t.asia/devel/php.php Please leave this initial header intact when distributing modified versions of this script. 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. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. License available at: http://www.gnu.org/copyleft/gpl.html */ require("conv_py.php"); ?> :: CEDICT search results ::

CEDICT search results :

",$part[2]); //convert chinese $part[0]=iconv($charset,"UTF-8",$part[0]); //convert pinyin $part[1]=convert_to_unicode($part[1]); $result[]=array('chi'=>$part[0],'pin'=>$part[1],'eng'=>$part[2]); } } return ($result); } //end function search function convert($input_is,$ext,$search) { if ($ext="b5") { $search=iconv("UTF-8","BIG5",$search); return ($search); } elseif ($ext="gb") { $search=iconv("UTF-8","GB2312",$search); return ($search); } } //end function convert function join_array($result_b5, $result_gb, $limit) { $result=array_merge($result_b5, $result_gb); if (!$limit) { //we don't want duplicates $result=array_unique2($result); //sort the array (!!! SHOULD BE ON PINYIN !!!) array_multisort($result,SORT_ASC); } return ($result); } //end function join_array //found recursivemakehash and array_unique2 on the array_unique page op php.net function recursivemakehash($tab) { if(!is_array($tab)) return md5($tab); $p = ''; foreach($tab as $a => $b) $p .= sprintf('%08X%08X', crc32($a), crc32(recursivemakehash($b))); return $p; } //end function recursivemakehash function array_unique2($input) { $dumdum = array(); foreach($input as $a => $b) $dumdum[$a] = recursivemakehash($b); $newinput = array(); foreach(array_unique($dumdum) as $a => $b) $newinput[$a] = $input[$a]; return $newinput; } //end function array_unique2 function print_result($result) { //start the table echo ""; //build the header echo ""; //build the results foreach($result as $value) { echo ""; } //colse the table echo "
Chinese Pinyin English
".utf8ToUnicodeEntities($value[chi])." $value[pin] $value[eng]
"; //always nice to know how many results there are found :) echo "
Found ".sizeof($result)." definitions."; }//end function print_result function utf2html ($utf2html_string) { $utf2html_retstr = ""; for ($utf2html_p=0; $utf2html_p>5 == 6): // 110x xxxx, 110 prefix for 2 bytes unicode $utf2html_p++; $utf2html_t = substr ($utf2html_string, $utf2html_p, 1); $utf2html_c2 = ord ($utf2html_t); $utf2html_c1 &= 31; // remove the 3 bit two bytes prefix $utf2html_c2 &= 63; // remove the 2 bit trailing byte prefix $utf2html_c2 |= (($utf2html_c1 & 3) << 6); // last 2 bits of c1 become first 2 of c2 $utf2html_c1 >>= 2; // c1 shifts 2 to the right $utf2html_n = dechex($utf2html_c1).dechex($utf2html_c2); $utf2html_retstr .= sprintf ("&#%03d;", hexdec($utf2html_n)); else: $utf2html_retstr .= $utf2html_c; endif; endfor; return $utf2html_retstr; } /** * taken from the utf8_decode-page from php.net * takes a string of utf-8 encoded characters and converts it to a string of unicode entities * each unicode entitiy has the form &#nnnnn; n={0..9} and can be displayed by utf-8 supporting * browsers * @param $source string encoded using utf-8 [STRING] * @return string of unicode entities [STRING] * @access public */ function utf8ToUnicodeEntities ($source) { // array used to figure what number to decrement from character order value // according to number of characters used to map unicode to ascii by utf-8 $decrement[4] = 240; $decrement[3] = 224; $decrement[2] = 192; $decrement[1] = 0; // the number of bits to shift each charNum by $shift[1][0] = 0; $shift[2][0] = 6; $shift[2][1] = 0; $shift[3][0] = 12; $shift[3][1] = 6; $shift[3][2] = 0; $shift[4][0] = 18; $shift[4][1] = 12; $shift[4][2] = 6; $shift[4][3] = 0; $pos = 0; $len = strlen ($source); $encodedString = ''; while ($pos < $len) { $asciiPos = ord (substr ($source, $pos, 1)); if (($asciiPos >= 240) && ($asciiPos <= 255)) { // 4 chars representing one unicode character $thisLetter = substr ($source, $pos, 4); $pos += 4; } else if (($asciiPos >= 224) && ($asciiPos <= 239)) { // 3 chars representing one unicode character $thisLetter = substr ($source, $pos, 3); $pos += 3; } else if (($asciiPos >= 192) && ($asciiPos <= 223)) { // 2 chars representing one unicode character $thisLetter = substr ($source, $pos, 2); $pos += 2; } else { // 1 char (lower ascii) $thisLetter = substr ($source, $pos, 1); $pos += 1; } // process the string representing the letter to a unicode entity $thisLen = strlen ($thisLetter); $thisPos = 0; $decimalCode = 0; while ($thisPos < $thisLen) { $thisCharOrd = ord (substr ($thisLetter, $thisPos, 1)); if ($thisPos == 0) { $charNum = intval ($thisCharOrd - $decrement[$thisLen]); $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); } else { $charNum = intval ($thisCharOrd - 128); $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); } $thisPos++; } $hexCode=strtoupper(dechex($decimalCode)); if ($thisLen == 1) $encodedLetter = "&#x".str_pad($hexCode, 3,"0", STR_PAD_LEFT).";"; else $encodedLetter = "&#x".$hexCode.";"; $encodedString .= $encodedLetter; } return $encodedString; } ?>