Send a PHP simple pseudo-original program, with the Mall collection

Source: Internet
Author: User
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.

  • 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.