【发布时间】:2014-10-09 09:19:07
【问题描述】:
用 PHP 指定 CSV 文件的行尾字符的正确方法是什么。我有这个脚本来编写 CSV 文件。
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
include_once("phpshared.php");
function get_node_urls( $nodeid ) {
$nodes = new SimpleXMLElement('linkcards.xml', null, true);
$nodesarray = $nodes->xpath("//LINKCARD[@ID='$nodeid']");
$linkstring = '';
$node = $nodesarray[0];
$i = 0;
foreach($node->LINKS->LINK as $url)
{
$linkstring .= $i.','.$url['ID'].','.$url->TITLE.','.$url->URL.'\r\n';
$i++;
}
echo $linkstring;
}
echo get_node_urls(trim($_REQUEST['nodeid']));
?>
如果我加载$linkstring,则每行末尾没有回车符。这些行应该是:
它们是:
0, id1, http://link1.com\r\n1, id2, http://link2.comCSV 阅读器将该行读取为:
id1 http://link1.com\r\n1是否有不同的方式来编写 CSV 的行尾?
【问题讨论】: