Problem using PHP to open text file - blank spaces are removed
Posted
by Reg H
on Stack Overflow
See other posts from Stack Overflow
or by Reg H
Published on 2010-05-10T19:43:05Z
Indexed on
2010/05/10
19:44 UTC
Read the original article
Hit count: 343
php
Hi All,
I'm trying to open and process ASCII files using PHP, but am having problems. The problem is that the blank spaces are removed, which I don't want to have happen, since the files are fixed width.
The PHP script I used is this:
$myFile = Test.SEG";
$file_handler = fopen ($myFile, r) or die ("Can't open SEG File.");
while (!feof($file_handler))
{
$dataline = fgets($file_handler);
echo $dataline, "
";
}
I tried pasting samples of the original file in here, but the spaces were removed here as well!
At this stage I'm just building the script in steps, getting one step working at a time, but this is as far as I've gotten. I plan to use substr() on '$dataline' to pick out the fields I need.
Any suggestions on how to keep the spaces intact? Something tells me it's something to do with encoding, but I don't know for sure.
Thanks!
© Stack Overflow or respective owner