Php 如何在CSV文件中正确写入数组?
我正在尝试将数组写入excel文件。我使用for循环生成数组。当我打印数组时,它会给我98条记录,但在excel文件中,它会写90条结果。若数组有150个结果,那个么它也会写入90个结果。这是我的密码Php 如何在CSV文件中正确写入数组?,php,csv,Php,Csv,我正在尝试将数组写入excel文件。我使用for循环生成数组。当我打印数组时,它会给我98条记录,但在excel文件中,它会写90条结果。若数组有150个结果,那个么它也会写入90个结果。这是我的密码 <?php error_reporting(0); ob_start(); ini_set('max_execution_time', 0); //300 seconds = 5 minutes ini_set('memory_limit', -1);
<?php
error_reporting(0);
ob_start();
ini_set('max_execution_time', 0); //300 seconds = 5 minutes
ini_set('memory_limit', -1);
include_once('classes/html_dom.php');
if ($_GET['q']) {
$mobile = $_GET['q'];
}
$filename = ucfirst($mobile);
for($i=1; $i<=4;$i++) {
//$target_url = 'https://www.awok.com/mobile-phones/ds-582/?brand='.$mobile.'&set-filter=Y&PAGEN_1='.$i.'';
$target_url = 'Source-Files/Awok-'.$filename.'-Mobile-'.$i.'.html';
$html = new simple_html_dom();
$html->load_file($target_url);
$SiteUrl = 'https://www.awok.com';
$products = array();
foreach($html->find('div.subcat_cat_item_text a ') as $link_1) {
foreach($link_1->find('p.subcat_cat_item_title') as $link_2) {
foreach($link_1->find('span.subcat_cat_item_newprice') as $link_3) {
array_push($products, array("Mobile Name" => $link_2->plaintext , "Link" => $SiteUrl.$link_1->href , "Price" => $link_3->plaintext));
}
}
}
/*echo '<pre>'; print_r($products); echo '</pre>';*/
$output = fopen("php://output",'w') or die("Can't open php://output");
header("Content-Type:application/csv");
header("Content-Disposition:attachment;filename=Awok ".$filename." Mobile List.csv");
header('Cache-Control: max-age=0');
foreach($products as $product) {
fputcsv($output, $product);
}
fclose($output) or die("Can't close php://output");
ob_flush();
}
?>
在平面文本编辑器中打开文件,检查是否有错误没有错误。如果print\u r给出了正确的结果,那么为什么它没有正确写入csv文件?对此问题有任何帮助吗?不知道看到了特定的数组是什么。如果我向您发送了文件,那么您可以检查它吗?在平面文本编辑器中打开文件,检查错误没有错误。如果print\u r给出了正确的结果,那么为什么它没有正确写入csv文件?对此问题有任何帮助吗?不知道看到特定数组时会发生什么。如果我向您发送文件,您可以检查它吗??