|
Posted by zeltus on 03/25/06 11:41
Hi
Can anyone help with the following... I'm trying to read multi-lines
from a flat file where a continuation is signalled by the line ending
ina backslash (ASCII 92)
Note 1: this is a windoze box
Note 2: My php.ini is set up with "auto_detect_line_endings = On"
Input file
------------
line 1 \
line 2 \
line 3
Code
-------
<?
$fp = "test.txt";
$is_more = 0;
while ($buf = @fgets($fp, 1024)) {
trim($buf);
if (substr($buf,-1) == _\\_) {
$line .= substr($buf,0,-1);
$is_more = 1;
continue;
} else {
$line = $is_more ? $line . $buf : $buf;
$is_more = 0;
}
echo $line;
}
Output
----------
[C:/] php -f cont_test.php
PHP Warning: Unexpected character in input: '\' (ASCII=92) state=1 in
C:\cont_test.php on line 6
PHP Warning: Unexpected character in input: '\' (ASCII=92) state=1 in
C:\cont_test.php on line 6
PHP Parse error: parse error, unexpected T_STRING in C:\cont_test.php
on line 6
The code is from the "PHP Developer's Cookbook" and altho' I've
discovered this error all over the 'net using google, I can't find a
cause or soln. for iut.
As ever, any help gratefully received....
Cheers
Bill
[Back to original message]
|