What is the correct way to specify the end of line character of a CSV file with PHP. I have this script to write a CSV file.
<?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'])); ?>
If I load $linkstring , there is no carriage return at the end of each line. Lines must be:
0, id1, http://link1.com
1, id2, http://link2.com
Instead, they:
0, id1, http: //link1.com \ r \ n1, id2, http://link2.com
The CSV reader reads this line as:
id1 http: //link1.com \ r \ n1
Is there any other way to write end of line for CSV?
user823527
source share