English 中文(简体)
缩略语
原标题:PHP end of line character for a csv file
  • 时间:2011-11-23 23:33:04
  •  标签:
  • php
  • csv

具体指明带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. 
 ;
       $i++;
}
echo $linkstring;

}

echo get_node_urls(trim($_REQUEST[ nodeid ]));

?>

如果I 装载 每一行的末尾均无运输回报。 应:

0, id1, http://link1.com
1, id2, http://link2.com

而是:

0, id1, http://link1.com
1, id2, http://link2.com

CSV读者读物如下:

id1 http://link1.com
1

Is there a different way of writing the end of line for a CSV?

最佳回答

needs to be enclosed in " instead of so that escape sequences will be interpreted (see documentation):

$linkstring .= $i. , .$url[ ID ]. , .$url->TITLE. , .$url->URL."
";
问题回答

在审视了整个网站之后,我发现,由于“停靠”的“自动探测线”无法发挥作用,这一问题已经解决。 只是将其放在你的法典上,它应当发挥作用。 它为我工作。

ini_set( auto_detect_line_endings ,TRUE);

自动取款机使你能够将档案作为常规档案加以整理,使用自动取款机。

$lines = file( your_csv_file.csv );

在我的案件中,Im已经用地板把CSV线路划为平地。

function parse_my_csv($filename) { 
    $lines = file($filename);
    $data = array();
    for($i=0;$i<count($lines);$i++) { 
       array_push($data, str_getcsv($lines[$i]));
    }
 return $data;
}




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...