bug? file(), newline (\n) comparison

From: Date: Wed, 16 May 2001 13:30:08 +0000
Subject: bug? file(), newline (\n) comparison
Groups: php.general 
Request: Send a blank email to php-general+get-53035@lists.php.net to get a copy of this message
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

« previous php.general (#53035) next »