PHP Kanji Conversion Pinyin Program

Source: Internet
Author: User
Tags chop explode flock ord prev

<?php


class Pinyin {


    var $data    = Array ("A", -20319), array ("AI", -20317), Array ("an", -20304), Array (" Ang ", -20295), Array (" AO ", -20292), array (" BA ", -20283), Array (" Bai ", -20265), Array (" ban ", -20257), Array (" bang ",-20242 ), Array ("Bao", -20230), Array ("Bei", -20051), Array ("Ben", -20036), Array ("Beng", -20032), Array ("BI", -20026), Array ("" Bian ", -20002), Array (" Biao ", -19990), Array (" Bie ", -19986), Array (" Bin ", -19982), Array (" Bing ", -19976), Array (" Bo ",- 19805), Array ("BU", -19784), Array ("Ca", -19775), Array ("Cai", -19774), Array ("Can", -19763), Array ("Cang",-19756), Array ("Cao", -19751), array ("Ce", -19746), Array ("CEng", -19741), Array ("Cha", -19739), Array ("Chai", -19728), Array (" Chan ", -19725), Array (" Chang ", -19715), Array (" Chao ", -19540), Array (" Che ", -19531), Array (" Chen ", -19525), Array (" Cheng ", -19515), Array (" Chi ", -19500), Array (" Chong ", -19484), Array (" Chou ", -19479), Array (" Chu ", -19467), Array (" Chuai ",- 19289), Array ("Chuan", -19288), Array ("Chuang", -19281), Array ("Chui", -19275), Array ("Chun", -19270), Array ("Chuo",- 19263), Array ("CI",-19261), Array ("Cong", -19249), Array ("Cou", -19243), Array ("CU", -19242), Array ("Cuan", -19238), Array ("Cui",-19235), Array ("Cun", -19227), Array ("CuO", -19224), Array ("Da", -19218), Array ("Dai", -19212), Array ("Dan", -19038), Array ("Dang ", -19023), Array (" DAO ", -19018), Array (" de ", -19006), Array (" Deng ", -19003), Array (" Di ", -18996), Array (" Dian ",-18977), Array ("Diao", -18961), Array ("Die", -18952), Array ("Ding", -18783), Array ("Diu", -18774), Array ("Dong", -18773), Array (" Dou ", -18763), Array (" Du ", -18756), Array (" Duan ", -18741), Array (" DUI ", -18735), Array (" Dun ", -18731), Array (" Duo ",- 18722), Array ("E", -18710), array ("en", -18697), Array ("ER", -18696), array ("FA", -18526), Array ("Fan", -18518), Array ("" Fang ", -18501), Array (" Fei ", -18490), Array (" Fen ", -18478), Array (" Feng ", -18463), Array (" fo ", -18448), Array (" Fou ",- 18447), Array ("Fu", -18446), Array ("GA", -18239), Array ("Gai", -18237), Array ("Gan", -18231), Array ("Gang",-18220), Array ("Gao", -18211), Array ("GE", -18201), Array ("GEi", -18184), Array ("Gen", -18183), Array ("Geng", -18181), Array (" Gong ", -18012), Array (" Gou ",-17997), Array ("gu", -17988), Array ("Gua", -17970), Array ("Guai", -17964), Array ("Guan", -17961), Array ("Guang",-17950), Array ("GUI", -17947), Array ("Gun", -17931), Array ("Guo", -17928), Array ("Ha", -17922), Array ("Hai", -17759), Array ("Han" , -17752), Array ("hang", -17733), Array ("Hao", -17730), Array ("he", -17721), Array ("Hei", -17703), Array ("Hen",-17701), Array ("Heng", -17697), Array ("a", -17692), Array ("Hou", -17683), Array ("Hu", -17676), Array ("Hua", -17496), Array (" Huai ", -17487), Array (" Huan ", -17482), Array (" Huang ", -17468), Array (" Hui ", -17454), Array (" Hun ", -17433), Array (" Huo ",- 17427), Array ("Ji", -17417), Array ("Jia", -17202), Array ("Jian", -17185), Array ("Jiang", -16983), Array ("Jiao",-16970), Array ("Jie", -16942), Array ("Jin", -16915), Array ("Jing", -16733), Array ("Jiong", -16708), array ("JIU", -16706), Array (" Ju ", -16689), Array (" Juan ", -16664), Array (" Jue ", -16657), Array (" June ", -16647), Array (" Ka ", -16474), Array (" Kai ",-16470 ), Array ("Kan", -16465), Array ("Kang", -16459), Array ("Kao", -16452), Array ("Ke", -16448), Array ("Ken", -16433), Array ("" Keng ", -16429), aRray ("Kong", -16427), Array ("Kou", -16423), array ("Ku", -16419), Array ("Kua", -16412), Array ("Kuai", -16407), Array ("" Kuan ", -16403), Array (" Kuang ", -16401), Array (" Kui ", -16393), Array (" Kun ", -16220), Array (" Kuo ", -16216), Array (" La ",- 16212), Array ("Lai", -16205), Array ("LAN", -16202), array ("Lang", -16187), Array ("Lao", -16180), Array ("le",-16171), Array ("Lei", -16169), Array ("Leng", -16158), array ("Li", -16155), Array ("Lia", -15959), Array ("Lian", -15958), Array (" Liang ", -15944), Array (" Liao ", -15933), Array (" Lie ", -15920), array (" Lin ", -15915), Array (" Ling ", -15903), Array (" Liu ",- 15889), Array ("Long", -15878), Array ("Lou", -15707), Array ("Lu", -15701), Array ("LV", -15681), Array ("Luan",-15667), Array ("Lue", -15661), Array ("LUN", -15659), Array ("Luo", -15652), Array ("Ma", -15640), Array ("Mai", -15631), Array ("Man" , -15625), Array ("Mang", -15454), Array ("Mao", -15448), Array ("Me", -15436), Array ("Mei", -15435), Array ("Men",-15419), Array ("Meng", -15416), Array ("Mi", -15408), Array ("Mian", -15394), Array ("Miao", -15385), Array ("Mie", -15377), Array ("" Min ", -15375), Array (" Ming ", -15369), Array ("Miu", -15363), array ("Mo", -15362), Array ("MoU", -15183), Array ("Mu", -15180), Array ("NA",-15165), Array ("Nai", -15158), Array ("Nan", -15153), Array ("Nang", -15150), Array ("Nao", -15149), Array ("NE", -15144), Array ("Nei ", -15143), Array (" nen ", -15141), Array (" Neng ", -15140), Array (" NI ", -15139), Array (" Nian ", -15128), Array (" Niang ",- 15121), Array ("Niao", -15119), Array ("Nie", -15117), Array ("NIN", -15110), Array ("Ning", -15109), Array ("NIU",-14941), Array ("Nong", -14937), Array ("Nu", -14933), Array ("NV", -14930), Array ("Nuan", -14929), Array ("Nue", -14928), Array ("Nuo ", -14926), array (" O ", -14922), Array (" ou ", -14921), Array (" Pa ", -14914), Array (" Pai ", -14908), Array (" Pan ",-14902), Array ("Pang", -14894), Array ("Pao", -14889), Array ("PEI", -14882), array ("pen", -14873), Array ("Peng", -14871), Array ("" Pi ", -14857", Array ("Pian", -14678), Array ("Piao", -14674), Array ("pie", -14670), array ("pin", -14668), Array ("ping",- 14663), Array ("Po", -14654), Array ("Pu", -14645), Array ("Qi", -14630), Array ("QIA", -14594), Array ("Qian", -14429), array ("Qiang", -14407), Array ("QiAo ", -14399), Array (" Qie ", -14384), Array (" Qin ", -14379), Array (" Qing ", -14368), Array (" Qiong ", -14355), Array (" Qiu ",- 14353), Array ("Qu", -14345), Array ("Quan", -14170), array ("que", -14159), Array ("Qun", -14151), Array ("ran",-14149), Array ("Rang", -14145), Array ("Rao", -14140), Array ("Re", -14137), array ("Ren", -14135), Array ("Reng", -14125), Array ("RI ", -14123), Array (" Rong ", -14122), Array (" Rou ", -14112), Array (" Ru ", -14109), Array (" Ruan ", -14099), Array (" Rui ",-14097) , Array ("Run", -14094), Array ("Ruo", -14092), Array ("sa", -14090), Array ("Sai", -14087), Array ("San", -14083), Array ("" Sang ", -13917), Array (" Sao ", -13914), Array (" se ", -13910), array (" Sen ", -13907), Array (" Seng ", -13906), Array (" Sha ",- 13905), Array ("Shai", -13896), Array ("Shan", -13894), Array ("Shang", -13878), Array ("Shao", -13870), Array ("she",-13859 ), Array ("Shen", -13847), Array ("Sheng", -13831), Array ("Shi", -13658), Array ("Shou", -13611), Array ("Shu",-13601), Array ("Shua", -13406), Array ("Shuai", -13404), Array ("Shuan", -13400), Array ("Shuang", -13398), Array ("Shui",-13395), Array ("Shun", -13391), array("Shuo", -13387), Array ("Si", -13383), Array ("song", -13367), Array ("Sou", -13359), Array ("Su", -13356), Array ("Suan",- 13343), Array ("Sui", -13340), Array ("Sun", -13329), Array ("suo", -13326), Array ("Ta", -13318), Array ("Tai",-13147), Array ("Tan", -13138), Array ("Tang", -13120), Array ("Tao", -13107), Array ("TE", -13096), Array ("Teng", -13095), Array ("Ti ", -13091), Array (" Tian ", -13076), Array (" Tiao ", -13068), Array (" Tie ", -13063), Array (" ting ", -13060), Array (" Tong ",- 12888), Array ("Tou", -12875), Array ("Tu", -12871), Array ("Tuan", -12860), Array ("Tui", -12858), Array ("Tun",-12852), Array ("Tuo", -12849), Array ("WA", -12838), Array ("Wai", -12831), Array ("WAN", -12829), Array ("Wang", -12812), Array ("Wei ", -12802), Array (" Wen ", -12607), Array (" Weng ", -12597), Array (" Wo ", -12594), Array (" WU ", -12585), Array (" XI ",-12556), Array ("Xia", -12359), Array ("Xian", -12346), array ("Xiang", -12320), Array ("Xiao", -12300), Array ("Xie", -12120), Array ( "Xin", -12099, Array ("Xing", -12089), Array ("Xiong", -12074), Array ("Xiu", -12067), Array ("Xu", -12058), Array ("Xuan",- 12039), Array ("Xue",-118), Array ("Xun", -11861), Array ("Ya", -11847), Array ("Yan", -11831), Array ("Yang", -11798), Array ("Yao", -11781), Array ( "Ye", -11604), Array ("Yi", -11589), Array ("Yin", -11536), Array ("Ying", -11358), Array ("Yo", -11340), Array ("Yong",- 11339), Array ("You", -11324), Array ("Yu", -11303), Array ("Yuan", -11097), Array ("Yue", -11077), Array ("Yun",-11067), Array ("Za", -11055), Array ("Zai", -11052), Array ("Zan", -11045), Array ("Zang", -11041), Array ("Zao", -11038), Array ("Ze" , -11024), Array ("Zei", -11020), Array ("Zen", -11019), Array ("Zeng", -11018), Array ("Zha", -11014), Array ("Zhai",-10838) , Array ("Zhan", -10832), Array ("Zhang", -10815), Array ("Zhao", -10800), Array ("Zhe", -10790), Array ("Zhen",-10780), Array ("Zheng", -10764), Array ("Zhi", -10587), Array ("Zhong", -10544), Array ("Zhou", -10533), Array ("Zhu", -10519), array ("Zhua", -10331), Array ("Zhuai", -10329), Array ("Zhuan", -10328), Array ("Zhuang", -10322), Array ("Zhui", -10315), Array ( "Zhun", -10309, Array ("Zhuo", -10307), Array ("Zi", -10296), Array ("Zong", -10281), Array ("Zou", -10274), Array ("Zu",- 10270), Array ("Zuan",-10262), Array ("Zui", -10260), Array ("Zun", -10256), Array ("Zuo",-10254));


function Get_one ($num) {


if ($num >0&& $num <160) {


return Chr ($num);


} elseif ($num <-20319| | $num >-10247) {


Return ";


} else {


For ($i =count ($this->data)-1; $i >=0; $i-) {if ($this->data[][1]<= $i) break;}


return $this->data[$i][0];


}


}


function Conver ($STR) {


$ret = "";


for ($i =0; $i <strlen ($STR); $i + +) {


$p =ord (substr ($str, $i, 1));


if ($p >160) {


$q =ord (substr ($str, + + $i, 1));


$p = $p *256+ $q-65536;


}


$ret. = $this->get_one ($p).   ';


}


return $ret;


}


}


?>

textclass.php

<?php


Class Ctbclass {


var $file = ' List.txt ';


var $index;


Create a file and write input


function Null_write ($new)


{


$f =fopen ($this->file, "w");


Flock ($f, LOCK_EX);


Fputs ($f, $new);


Fclose ($f);


}


Add data log to file end


function Add_write ($new) {


$f =fopen ($this->file, "a");


Flock ($f, LOCK_EX);


Fputs ($f, $new);


Fclose ($f);


}


With the return of ReadFile (), convert one row of data into a one-dimensional array


function Make_array ($line) {


$array = Explode ("x0e", $line);


return $array;


}


Converts a one-dimensional array to one row of data


function Join_array ($line) {


$array = Join ("x0e", $line);


return $array;


}


Returns the total number of rows in a data file


function Getlines () {


$f =file ($this->file);


return count ($f);


}


Returns the data record for the next row (standby)


function Next_line () {


$this->index= $this->index++;


return $this->get ();


}


Returns the data record for the previous row (standby)


function Prev_line () {


$this->index= $this->index--;


return $this->get ();


}


Returns the data record data for the current row is small


function Get () {


$f =fopen ($this->file, "R");


Flock ($f, lock_sh);


For ($i =0 $i <= $this->index; $i + +) {


$rec =fgets ($f, 1024);


}


$line =explode ("x0e", $rec);


Fclose ($f);


return $line;


}


Returns the data record data for the current row is larger


function Get_big_file () {


$f =fopen ($this->file, "R");


Flock ($f, lock_sh);


For ($i =0 $i <= $this->index; $i + +) {


$rec =fgets ($f, 1024*5);


}


$line =explode ("x0e", $rec);


Fclose ($f);


return $line;


}


Open a data file---return the contents of a file with a one-dimensional array


function Read_file () {


if (file_exists ($this->file)) {


$line =file ($this->file);


}


return $line;


}


Open a data file---return the contents of a file in a two-dimensional array


function OpenFile () {


if (file_exists ($this->file)) {


$f =file ($this->file);


$lines = Array ();


foreach ($f as $rawline) {


$tmpline = Explode ("x0e", $rawline);


Array_push ($lines, $tmpline);


}


}


return $lines;


}


Pass in an array, merge into one row of data, rewrite the entire file


function overwrite ($array) {


$newline = Implode ("x0e", $array);


$f = fopen ($this->file, "w");


Flock ($f, LOCK_EX);


Fputs ($f, $newline);


Fclose ($f);


}


Add a row of data to the end of a file


function Add_line ($array, $check _n=1) {


$s =implode ("x0e", $array);


$f =fopen ($this->file, "a");


Flock ($f, LOCK_EX);


Fputs ($f, $s);


if ($check _n==1) fputs ($f, "n");


Fclose ($f);


}


Inserts a row of data to the front of the file


function Insert_line ($array) {


$newfile = Implode ("x0e", $array);


$f = fopen ($this->file, "R");


Flock ($f, lock_sh);


while ($line = fgets ($f, 1024)) {


$newfile. = $line;


}


Fclose ($f);


$f = fopen ($this->file, "w");


Flock ($f, LOCK_EX);


Fputs ($f, $newfile);


Fclose ($f);


}


Update all eligible data records for larger cases of byte data per row


function Update ($column, $query _string, $update _array) {


$update _string = Implode ("x0e", $update _array);


$newfile = "";


$FC =file ($this->file);


$f =fopen ($this->file, "R");


Flock ($f, lock_sh);


for ($i =0; $i <count ($FC); $i + +) {


$list = Explode ("x0e", $FC [$i]);


if ($list [$column]!= $query _string) {


$newfile = $newfile. Chop ($FC [$i]). " n ";


} else {


$newfile = $newfile. $update _string;


}


}


Fclose ($f);


$f =fopen ($this->file, "w");


Flock ($f, LOCK_EX);


Fputs ($f, $newfile);


Fclose ($f);


}


Update all eligible data records for smaller byte data per row


function Update2 ($column, $query _string, $update _array) {


$newline = Implode ("x0e", $update _array);


$newfile = "";


$f = fopen ($this->file, "R");


Flock ($f, lock_sh);


while ($line = fgets ($f, 1024)) {


$tmpLine = Explode ("x0e", $line);


if ($tmpLine [$column] = = $query _string) {


$newfile. = $newline;


} else {


$newfile. = $line;


}


}


Fclose ($f);


$f = fopen ($this->file, "w");


Flock ($f, LOCK_EX);


Fputs ($f, $newfile);


Fclose ($f);


}


Delete all eligible data records for larger cases of byte data per row


function Delete ($column, $query _string) {


$newfile = "";


$FC =file ($this->file);


$f =fopen ($this->file, "R");


Flock ($f, lock_sh);


for ($i =0; $i <count ($FC); $i + +) {


$list = Explode ("x0e", $FC [$i]);


if ($list [$column]!= $query _string) {


$newfile = $newfile. Chop ($FC [$i]). " n ";


}


}


Fclose ($f);


$f =fopen ($this->file, "w");


Flock ($f, LOCK_EX);


Fputs ($f, $newfile);


Fclose ($f);


}


Delete all eligible data records for smaller byte data per row


function Delete2 ($column, $query _string) {


$newfile = "";


$f = fopen ($this->file, "R");


Flock ($f, lock_sh);


while ($line = fgets ($f, 1024)) {


$tmpLine = Explode ("x0e", $line);


if ($tmpLine [$column]!= $query _string) {


$newfile. = $line;


}


}


Fclose ($f);


$f = fopen ($this->file, "w");


Flock ($f, LOCK_EX);


Fputs ($f, $newfile);


Fclose ($f);


}


Gets the maximum value of a field in a file


function Get_max_value ($column) {


$tlines = File ($this->file);


for ($i =0; $i <=count ($tlines); $i + +) {


$line =explode ("x0e", $tlines [$i]);


$get _value[]= $line [$column];


}


$get _max_value = max ($get _value);


return $get _max_value;


}





Returns all eligible data in a two-dimensional array based on whether a field in the data file contains $query_string


function Select ($column, $query _string) {


$tline = $this->openfile ();


$lines = Array ();


foreach ($tline as $line) {


if ($line [$column] = = $query _string) {


Array_push ($lines, $line);


}


}


return $lines;


}


function is as simple as function select (), the speed may be slightly elevated


function Select2 ($column, $query _string) {


if (file_exists ($this->file)) {


$tline = $this->read_file ();


foreach ($tline as $tmpLine) {


$line = $this->make_array ($tmpLine);


if ($line [$column] = = $query _string) {


$lines []= $tmpLine;


}


}


}


return $lines;


}


Returns the first qualifying data in a one-dimensional array based on whether a field in the data file contains $query_string


function Select_line ($column, $query _string) {


$tline = $this->read_file ();


foreach ($tline as $tmpLine) {


$line = $this->make_array ($tmpLine);


if ($line [$column] = = $query _string) {


return $line;


Break


}


}


}


Select Next/prev Line (Next_prev ==> 1/next, 2/prev) by CX


function Select_next_prev_line ($column, $query _string, $next _prev) {


$tline = $this->read_file ();


$line _key_end = count ($tline)-1;


$line _key =-1;


foreach ($tline as $tmpLine) {


$line _key++;


$line = $this->make_array ($tmpLine);


if ($next _prev = = 1) {//next?


if ($line [$column] = = $query _string) {


if ($line _key = = 0) {


return 0;


} else {


$line _key_up = $line _key-1;


return $up _line;


}


} else {


$up _line = $line;


}


} elseif ($next _prev = = 2) {//prev?


if ($line [$column] = = $query _string) {


if ($line _key = = $line _key_end) {


return 0;


} else {


$line _key_down = $line _key + 1;


Break


}


}


} else {


return 0;


}


}


$down _line = $this->make_array ($tline [$line _key_down]);


return $down _line;


}

}

$file =fopen (' List.txt ', "A +");
if ($file = = FALSE) exit (' <font color=red> cannot create or open list.txt</font> ');

function __urljudge ($url) {
$suffixes = "com|net|org|gov|biz|com.tw|com.hk|com.ru|net.tw|net.hk|net.ru|info|cn|com.cn|net.cn|org.cn|gov.cn| mobi|name|sh|ac|la|travel|tm|us|cc|tv|jobs|asia|hn|lc|hk|bz|com.hk|ws|tel|io|tw|ac.cn|bj.cn|sh.cn|tj.cn|cq.cn| he.cn|sx.cn|nm.cn|ln.cn|jl.cn|hl.cn|js.cn|zj.cn|ah.cn|fj.cn|jx.cn|sd.cn|ha.cn|hb.cn|hn.cn|gd.cn|gx.cn|hi.cn| SC.CN|GZ.CN|YN.CN|XZ.CN|SN.CN|GS.CN|QH.CN|NX.CN|XJ.CN|TW.CN|HK.CN|MO.CN|ORG.HK ";
if (!eregi (www.)? ([a-za-z0-9-]) +. ($suffixes) $ ", $url)) {
echo "<script language= ' JavaScript ' >alert (' you enter the URL does not conform to the specification, please re-enter! '); </script> ";
Exit
}else {return $url;}
}

function Get_real_ip () {
$ip =false;
if (!empty ($_server["HTTP_CLIENT_IP"])) {
$ip = $_server["Http_client_ip"];
}
if (!empty ($_server[' http_x_forwarded_for ')) {
$ips = Explode (",", $_server[' http_x_forwarded_for '));
if ($IP) {array_unshift ($ips, $ip); $ip = FALSE;}
for ($i = 0; $i < count ($ips); $i + +) {
if (!eregi ("^ (10|172.16|192.168).", $ips [$i])) {
$ip = $ips [$i];
Break
}
}
}
Return ($ip $ip: $_server[' remote_addr ']);
}

$ip =get_real_ip ();

$text _class=new Ctbclass ();

$date =mktime (Date (H) -24, date (i), date (s), date (m), date (d), date (Y));

$history = $text _class->openfile ();
for ($i =0; $i <count ($history); $i + +) {
 if ($history [$i][2] < $date) {
   $text _class- >delete2 (2, $history [$i][2]);
 }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.