php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34824 Error in fgetcsv parsing with backslashes
Submitted: 2005-10-11 10:02 UTC Modified: 2005-10-11 14:17 UTC
From: decryptus at gmail dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.4.0 OS: Linux debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: decryptus at gmail dot com
New email:
PHP Version: OS:

 

 [2005-10-11 10:02 UTC] decryptus at gmail dot com
Description:
------------
The function fgetcsv has a problem when I parse a csv file.

If you parse a csv for example with delimeter pipe ("|") and you backslashes a pipe, the function shouldn't take it that a delimeter.

Reproduce code:
---------------
csv_file.csv content:

foo|foo_1\|foo_2

----------------------------------
fgetcsv.php content:

<?php
	$handle = fopen('csv_file.csv','r');
	while(($line = fgetcsv($handle,1000,'|')) !== false)
	{
		print '<pre>'; print_r($line); print '</pre>';
	}
?>


Expected result:
----------------
Array
(
    [0] => foo
    [1] => foo_1|foo_2
)

Actual result:
--------------
Array
(
    [0] => foo
    [1] => foo_1\
    [2] => foo_2
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-11 14:17 UTC] tony2001@php.net
The CSV file should contain 
foo|"foo_1\|foo_2"
if you want it to be parsed correctly.
Try with Excel/Spreadsheet and you'll get the same result.
No bug here.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 10 07:01:31 2024 UTC