Home > Backend Development > PHP Tutorial > Send a simple pseudo-original program in PHP to cooperate with shopping mall collection

Send a simple pseudo-original program in PHP to cooperate with shopping mall collection

WBOY
Release: 2016-07-29 08:43:56
Original
1103 people have browsed it

Copy code The code is as follows:


$arr=array();
$arr['good']='bad';
$arr['bad']='no 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 Import from the file into the database

Copy the code The code is as follows:

//Write the array in the file into 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)//If it does not exist, insert
{
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";
?>

The above has introduced a simple pseudo-original program in PHP to cooperate with the mall collection, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template