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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 16:01:36 2025 UTC