Computer Science Canada

PHP for parsing?

Author:  Justin_ [ Fri Aug 04, 2006 1:46 pm ]
Post subject:  PHP for parsing?

Hey guys,
I have to parse some ascii text files and I thought it might be easier using a scripting language. But unlike C there is no obvious way to access variables and manipulate them (character by character).

My original plan was to put the filestream in a buffer and manipulate it on-the-fly so to speak, meaning before the data is outputted to the new file it would be parsed. A way to do that might be to read the original file into a variable and then run scans on the bytes in the variable to see if any match and then patch them accordingly...

Being highly unskilled this is the idea I have but cannot implement because I can't find any way to access individual bytes in the variable (with PHP). So if someone knows of a way you could either tell me about it or explain a better way of parsing. Thanks for your time.

Author:  md [ Fri Aug 04, 2006 1:48 pm ]
Post subject: 

$string[0] will get you the first character. Mostly though there isn't a huge need for accessing individual characters with php. The built in string functions are immensely powerful.

Author:  Justin_ [ Fri Aug 04, 2006 1:55 pm ]
Post subject: 

Oh, my mistake, yeah that is fairly straight forward... I'll find a listing of the string functions and I should be good to go. Thanks again.

Author:  Justin_ [ Fri Aug 04, 2006 2:07 pm ]
Post subject: 

V sbhaq n terng yvfgvat bs gur fgevat shapgvbaf... Vapyhqvat gur ebg13 shapgvba nf lbh pna ernqvyl frr.

Author:  md [ Fri Aug 04, 2006 4:12 pm ]
Post subject: 

Methinks you've discovered rot13, good job; but please don't spam (even if you did create the topic).


: