note 2215 deleted from fread by ronabop
| From: | ronabop@php.net | Date: | Sun, 27 Aug 2000 11:59:01 +0000 |
| Subject: | note 2215 deleted from fread by ronabop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-3497@lists.php.net to get a copy of this message | ||
I am trying to use the fread() function to read an XML-like file, sort of a homegrown parser. The
files and code samples are below.
The output is stripped of the "tags" I had planned to use to parse for and grab the values
between. When I change the file name to a olumnar-
formatted text file, the output is has white spaces truncated, and appears as it should be. HOW CAN
I AVOID THE TAG STRIPPING USING fread()?
>>> SAMPLE CODE below:
$CongressXml = "congress.xml";
if ( file_exists ( $CongressXml ) ) {
$fp = fopen ( $CongressXml, 'r' ) or die( "Cannot open congress.xml" );
$buffer = fread( $fp, filesize( $CongressXml ) );
fclose( $fp );
$LenOfBuffer = StrLen( $buffer );
$iEndPos = 0;
$iStartPos = 0;
} else {
echo "Missing congress.xml";
}
>>> congress.xml sample below:
<REPRESENTATIVE>
<STATE>AK</STATE>
<FULLNAME>Alaska</FULLNAME>
<LASTNAME>Young</LASTNAME>
<FIRSTNAME>Don</FIRSTNAME>
<DISTRICT>AL</DISTRICT>
<PARTY>R</PARTY>
<EMAIL>Don.Young@mail.house.gov</EMAIL>
</REPRESENTATIVE>
>>> Sample output from fread() of congress.xml:
AK Alaska Young Don AL R Don.Young@mail.house.gov AL Alabama
Callahan Sonny 1 R sonny.callahan@mail.house.gov AL Alabama Everett Terry 2
R Terry.Everett@mail.house.gov AL Alabama Riley Bob 3 R
>>> congressemails.txt sample below:
AK R Stevens, Ted Senator_Stevens@stevens.senate.gov
*AK R Murkowski, Frank http://murkowski.senate.gov/webmail.html
AL R Sessions, Jeff senator@sessions.senate.gov
AL R Shelby, Richard senator@shelby.senate.gov
>>> Sample output from fread() of congressemails.txt:
AK R
Stevens, Ted Senator_Stevens@stevens.senate.gov *AK R Murkowski, Frank
http://murkowski.senate.gov/webmail.html AL R
Sessions, Jeff
senator@sessions.senate.gov AL R Shelby, Richard senator@shelby.senate.gov
AR D Lincoln, Blanche blanche_lincoln@lincoln.senate.gov AR R Hutchinson,