Copy CodeThe code is as follows:
$arr =array ();
$arr [' Good ']= ' bad ';
$arr [' bad ']= ' not bad ';
$arr [' Bad ']= ' good ';
$arr [' Not bad ']= ' bad ';
$str = "We are not good";
Echo Strtr ($str, $arr);
Output we are bad not bad
?>
So the problem is solved very well. Build a database of your own to collect synonyms
The key two programs are import databases and export files.
word2db.php importing from a file into a database
Copy the Code code as follows:
Writes an array from a 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 '");//detection already exists
$CT = @mysql_fetch_array ($CT);
$ct = $ct [0];
if ($ct <=0)//does not exist insert
{
mysql_query ("INSERT into". Table (' keywords '). " (K1,k2,pinyin) VALUES (' $key ', ' $val ', ' $pinyin ') ' or Die ' ("error");
}
}
echo "Insert success! ";
?>
db2word.php importing from a database to a file
Copy the Code code as follows:
Writes the database to a file as 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]." '; r\n ";
}
$str. = "?>";
File_put_contents ("keyword.php", $str);
echo "Export Success";
?>
The above introduces the introduction of a simple pseudo-original PHP program, with the mall collection, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.