FreeBSD Port: php4-4.3.5: fgetcvs problem with "\n" in delimited data

Markus Pfister pfm at bluewin.ch
Sat Apr 10 05:17:49 PDT 2004


Hi Ale,

If I sent this mail to the wrong (not in charge) person, please
apologize.
The folks running our webserver run the php4 4.3.5 FreeBSD port from the
http://www.freshports.org/lang/php4 site.

Consider the following code:

<?php
$fn = tempnam( '/tmp', 'testfile' );
if( $fp = fopen( $fn, 'w' ) )
{
        fwrite( $fp, "\"one\",\"a\nline\nwith\nlinebreaks\n\"" );
        fclose($fp);
        $fp = fopen($fn, "r");
        $row = 1;
        while (($data = fgetcsv($fp, 10000, ",")) !== FALSE)
        {
                $num = count($data);
                echo "<p> $num fields in line $row: <br />\n";
                $row++;
                for ($c=0; $c < $num; $c++)
                {
                        echo nl2br($data[$c]) . "<br />\n";
                }
        }
        fclose($fp);
}
?>

Problem description:
It seems, that former versions of fgetcsv was able to parse delimited
data fields containing line breaks (\n), where the 4.3.5 version (see
http://www.kim-dojo.ch/php/kisgb/ck98.php for detailed information)
"forgets" that data.

Sample code output:
This code produces on a Linux box with php 4.3.1 or 4.3.5 installed:

Content-type: text/html
X-Powered-By: PHP/4.3.1

<p> 2 fields in line 1: <br />
one<br />
a<br />
line<br />
with<br />
linebreaks<br />
<br />

On a FreeBSD System with php 4.3.5 installed the output is:

<p> 2 fields in line 1: <br />
one<br />
<br />

Could someone try to reproduce the described behaviour and let me know
if my observations are correct or if I simply did something wrong.
Regards
Markus Pfister
Visit http://www.kim-dojo.ch





More information about the freebsd-ports mailing list