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
?>
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!";
?> ;
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";
?>