Send a php simple pseudo-original program, used in combination with the mall collection

Source: Internet
Author: User

Copy codeThe Code is as follows:
<? Php
$ Arr = array ();
$ Arr ['hao'] = 'bad ';
$ Arr ['bad'] = 'bad ';
$ Arr ['bad'] = 'good ';
$ Arr ['bad'] = 'bad ';
$ Str = "Are we good ";
Echo strtr ($ str, $ arr );
// Output is not bad.
?>

So the problem is solved. Build a database to collect Synonyms
The two key programs are importing databases and exporting files.
Import word2db. php from file to database
Copy codeThe Code is as follows:
<? Php
// Write the array in the file into the database
Require ("conn. php ");
@ Require ("keyword. php ");
Mysql_query ("delete from". table ('keyword ')."");
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 ('keyword '). "where k1 = '$ key' and k2 =' $ val '"); // check whether the specified object already exists.
$ Ct = @ mysql_fetch_array ($ ct );
$ Ct = $ ct [0];
If ($ ct <= 0) // insert if it does not exist
{
Mysql_query ("insert ". table ('keyword '). "(k1, k2, pinyin) values ('$ key',' $ val ',' $ pinyin')") or die ("error ");
}
}
Echo "inserted successfully! ";
?>

Import db2word. php from database to file
Copy codeThe Code is as follows:
<? Php
// Write the database to a file as an array
Require ("conn. php ");
$ Res = mysql_query ("select k1, k2 from". table ('keyword ')."");
$ Str = "<? Php \ r \ n ";
While ($ rs = mysql_fetch_array ($ res ))
{
$ Str. = "\ $ keyword ['". $ rs [0]. "'] = '". $ rs [1]. "'; \ r \ n ";
}
$ Str. = "?> ";
File_put_contents ("keyword. php", $ str );
Echo "exported ";
?>

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.