Copy code The code is as follows:
$arr=array();
$arr[' good']='bad';
$arr['bad']='not bad';
$arr['bad']='good';
$arr['not bad' ]='bad';
$str="Are we good or not";
echo strtr($str,$arr);
//Output whether we are bad or not
?>
So the problem is easily solved. I built a database myself to collect synonyms
The two key procedures are importing the database and exporting the file.
word2db.php is imported from the file into the database
Copy the code The code is as follows:
//Write the array in the file to the database
require("conn.php");
@require("keyword.php");
mysql_query("delete from ".table( 'keywords')."");
foreach($keyword as $key=>$val)
{
//$key=iconv('utf-8','gbk',$ key);
//$val=iconv('utf-8','gbk',$val);
$pinyin=getfirstchar($key);
$ct=mysql_query("select count (*) from ".table('keywords')." where k1='$key' and k2='$val'");//Check whether it already exists
$ct=@mysql_fetch_array($ct);
$ct=$ct[0];
if($ct<=0)//insert if it does not exist
{
mysql_query("insert into ".table('keywords'). "(k1,k2,pinyin) values('$key','$val','$pinyin')") or die("Error");
}
}
echo "Insertion successful ! ";
?>
db2word.php Import from database to file
Copy code The code is as follows:
//Write the database to the file in the form of an array
require("conn.php");
$res=mysql_query("select k1, k2 from ".table('keywords')." ") ;
$str="while($rs=mysql_fetch_array($res))
{
$str .="$keyword['".$rs[0]."']='".$rs[1]."';rn";
}
$str.="?> ;";
file_put_contents("keyword.php",$str);
echo "Export successful";
?>
http://www.bkjia.com/PHPjc/322558.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322558.htmlTechArticleCopy the code as follows: ?php $arr=array(); $arr['good']='bad '; $arr['bad']='not bad'; $arr['bad']='good'; $arr['not bad']='bad'; $str="Are we good" ; echo strtr($str,$arr);...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn