You are here: reading multi-lines in a file... « PHP Programming Language « IT news, forums, messages
reading multi-lines in a file...

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация