php导出数据excel有专门的库,当导出少量数据的时候速度很快,但是当数据量大的时候就会存在服务器内存不够之类的.
所以在导出大量数据的时候就应该分页查询数据,避免服务器宕机.正好PHP提供了fputcsv函数可以将数据写入到csv文件中.
这样我们就可以使用PHP对数据进行分页查询,再写入到csv文件中.
使用 simplexml_load_string函数就可以了,例子程序代码:
php
$string = XML
returnsms
returnstatusstatus/returnstatus
messagemessage/message
/returnsms
XML;
$xml = simplexml_load_string($string);
echo 'returnstatus:',$xml-returnstatus,"\n";
echo 'message:',$xml-message,"\n";
print_r($xml);
PHP导出ecxcel的 要点是,输出文件header信息.
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=test_data.xls");
实例如下:
php?
require_once(dirname(__FILE__).'/include/config.inc.php');?//系统文件入口
header("Content-type:application/vnd.ms-excel");?//excel头信息
table?class="table?table-bordered?table-hover?table-striped?tablesorter"?border="1"
thead
tr
th编号:?/th
th门店?/th
th手机号码?/th
th最后访问时间:?/th
/tr
/thead
tbody
//数据库查询?
$dosql-Execute("select?*?from?link_log?order?by?id?desc");
$i=$dosql-GetTotalRow();
while($result=$dosql-GetArray()){
$host=$result['host'];?//门店
$mobile=$result['mobile'];?//手机号码
$link_time=date("Y-m-d?H:i:s",$result['link_time']);
td?php?echo?$i;?/td
td?php?echo?$host;?/td
td?php?echo?$mobile;?/td
td?php?echo?$link_time;?/td
$i--;
}?
/tbody
/table
localAddress是一个json对象,
$a='{"city":"广州市",?"province":"广东省"}';
$a?=?json_decode($a,true);
$b?=?$a['province'].?$a['city'];
echo?$b;
以上就是土嘎嘎小编为大家整理的php调用接口导出数据相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!