最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php 数据库内容以数组形式保存文件中
时间:2010-10-20 编辑:简简单单 来源:一聚教程网
$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 "导出成功";
//方法二
$f=file_get_contents("w1.txt");
$f=str_replace("rn","
",$f);//替换换行符
$arr=explode("
",$f);
$str="
foreach($arr as $t)
{
$rs=explode("|",$t);
//不能包含?等特殊符号
$str .="$keyword['".str_replace("?","",$rs[0])."']='".str_replace("?","",$rs[1])."';rn";
}
$str.="?>";
file_put_contents("keyword.php",$str);
echo "导出成功";
//conn.php文件
$conn=mysql_connect($mysql_host,$mysql_user,$mysql_password) or die('连接服务器出错');
mysql_select_db($mysql_db) or die("选择数据库出错");
mysql_query("set names 'gbk'");
function table($t)
{
global $mysql_table_prefix;
return $mysql_table_prefix.$t;
}
?>
-
上一个: 几种php 删除数组元素方法
-
下一个: 一款经典php mysql分页程序
相关文章
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31
- Laravel异常上下文解决教程 10-24
- php数组查询元素位置方法介绍 10-24