php database content is saved as an array of files

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags array code content file files it is keywords mysql

The contents of the database tutorial to save the file in an array Here to save the commonly used content in the database to a standard php format file, it is also more convenient to use, the following code.
* /
$ res = mysql tutorial _query ("select k1, k2 from" .table ('keywords'). "");
$ str = "<? php rn";
while ($ rs = mysql_fetch_array ($ res))
{

$ rss [0]. "'] ='". $ rs [1]. "'; rn";
}
$ str. = "?>";
file_put_contents ("keyword.php", $ str);
echo "export success";

//Method Two

$ f = file_get_contents ("w1.txt");
$ f = str_replace ("rn", "<br>", $ f); // Replace line breaks
$ arr = explode ("<br>", $ f);
$ str = "<? php rn";
foreach ($ arr as $ t)
{
$ rs = explode ("|", $ t);
// can not contain? Other special symbols
$ str. = "$ keyword ['". str_replace ("?", "", $ rs [0]).' ']' '' '. str_replace ("?", "", $ rs [1]). "'; rn";

}
$ str. = "?>";
file_put_contents ("keyword.php", $ str);
echo "export success";

//conn.php file
$ conn = mysql_connect ($ mysql_host, $ mysql_user, $ mysql_password) or die ('Connection Server Error');
mysql_select_db ($ mysql_db) or die ("Select database error");
mysql_query ("set names 'gbk'");
function table ($ t)
{
global $ mysql_table_prefix;
return $ mysql_table_prefix. $ t;
}
?>

Related Article

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.