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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
43 - 24 = ?
Subscribe to this entry?

 
 [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: Mon May 20 18:01:36 2024 UTC