Can I have some parsing help?
Posted: Thu May 11, 2006 2:22 pm
Weirdan | Please use
So I have the entire file in one string, now how can I go through it char by char?
Thanks
Weirdan | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi all. I coming from a Java background and I'm having a little trouble with parsing.
I have an old data file that contains non-ASCII characters. I need to parse these out and replace them with entities.
I also need to keep track of whether I am within a backslash or not. I figure I can do this with a state variable that is either on or off.
My main problem is figuring out how to go through the file character by character. I think I need to do it this way so that I can keep track of the backslashes.
Here is what I have so far:Code: Select all
<?php
$fp = fopen( "test.txt", "r+" );
if(!$fp)
{
echo "Couldn't open the data file.";
exit;
}
$contents = fread($fp, filesize("test.txt"));
echo $contents;
fclose($fp);
?>Thanks
Weirdan | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]