Recently, a project involving the conversion of Simplified Chinese characters to Traditional Chinese characters, online search, search for a long time, found that no one can use, but ultimately it is a process of understanding. The idea of most articles on the internet is to find the corresponding Chinese characters in a simplified, traditional corresponding table, and then to replace them, the principle is so simple.
No way, can not find ready-made, you have to stand on the shoulders of predecessors to create their own. What makes me feel comfortable is to find a Chinese simplified, traditional corresponding data table, according to their own ideas to organize it into a key in simplified characters, traditional characters for the value of a one-dimensional array, similar to the following array structure:
$data =array (' side ' => ' flank ', ' factory ' => ' plant ');
Well, according to this structure, the corresponding replacement method is as follows:
function j2f ($str) {
if (trim ($str) = = ') {return
';
}
$fstr = ';
Include ' j2fdata.php '///This data file has the download address
$count =mb_strlen ($str, ' utf-8 ');
For ($i =0 $i <= $count; $i + +) {
$jchar =mb_substr ($str, $i, 1, ' utf-8 ');
The $fantidata array used here is the $fchar =isset defined in the j2fdata.php file
($fantiData [$jchar])? $fantiData [$jchar]: $jchar;
$fstr. = $fchar;
}
return $fstr;
}
The specific usage is as follows:
<?php
$str = ' This site is a PHP Programmer's working life notes, this site contains the PHP Network programming Learning tutorials, database (mainly MySQL and Access database) tutorials, JAVASCRIPT,JQUERY,DIV+CSS, Html,windows systems, Linux systems, and health-care learning notes and the accumulation of life experience! ';
echo j2f ($STR);
The results will be output as follows:
This site is a PHP program member's work life note, this site contains the PHP network learning tutorial, data library (mainly MySQL and Access data library) tutorial, javascript,jquery,div+css,html,windows system, The Linux system as well as the health and nutrition learning notes and life experience of the cumulative!
PHP Simplified => Traditional array data file download