Re: bug? file(), newline (\n) comparison
| From: | Chris Lee | Date: | Wed, 16 May 2001 12:48:44 +0000 |
| Subject: | Re: bug? file(), newline (\n) comparison | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-53046@lists.php.net to get a copy of this message | ||
on my linux based system
echo ord("\n");
is 10 which is 0A in hex. windows machings usually consider newline to be 0A0D or 0D0A mac's
usually are 0D I would convert your file. I have to do this often with file uploads.
// convert all 0A0D and 0D0A to 0A0A
$data = str_replace(chr(13), chr(10), $data);
// convert all 0A0A to 0A
$data = str_replace(chr(10).chr(10), chr(10), $data);
this will standardize it for you.
--
Chris Lee
lee@mediawaveonline.com
""Hannes Schmiderer"" <johannes.schmiderer@aon.at> wrote in message news:9dtv8b$cud$1@toye.p.sourceforge.net...
Hi!
$astrData = file($astrCounterFile[$i]);
echo "|\n|<br>";
echo "|" . $astrData[0] . "|<br>";
echo "|" . $astrData[1] . "|<br>";
//$astrData[1] = "\n";
//echo "|" . $astrData[1] . "|<br>";
echo "|" . $astrData[2] . "|<br>";
for($k = 0; strcmp($astrData[$k] , "\n") && ($k < 50); $k++)
// for($k = 0; ($astrData[$k] <> "\n") && ($k < 50); $k++)
{
echo "|" . $astrData[$k] . "|" . "<br>";
}
I use 4.0.5 Win32 CGI, At the moment FTP at my host is down, so I cannot
test it on another system.
I have a textfile with line breaks and some empty lines in it. I read it
with file() into an array. When I output the lines, I can see in the hex
editor that the second line contains only a newline (0D 0A). When I output
"\n" it is 0D 0A, too.
The strange thing is, that, when I compare this array element (with the
emtpy line) with "\n" It is never true! Not with strcmp, strncmp or <>.
When I remove the comments (//) and set $astrData[1]="\n" explicit it works!
Note that echo "|" . $astrData[1] . "|<br>"; befor and after the
assignment
have the same output (in hex editor).
Is this a type problem, are newlines internaly handled differently to usual
strings?
Thanx for help
Hannes
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net