This (regular expressions and stuff) is something I don't do much. I allways try to look for another way of doing it before I do use it. Most of the time, I don't have to. It's one of the ugliest looking things I've ever seen in programming, but anyone that can read and understand line after line of that stuff gets credit from me.
Anyways, I've had need of preg_replace() and ereg() and to be honest with you, I'm not sure of the difference between the two. I'm not sure I care.
Anyways, what I was doing in one of those instances was looking for all data between two points in an document. Here is a code snippet.
Code: Select all
if(strstr($story, "<!--- start title --->"))
{
$search=ereg("<!--- start title --->(.*)<!--- end title --->", $story, $info);
}
Now the var $info is actually an array (
php.net/ereg) and you should fiddle with the array just a tad to get the info out of it that you want.
The "(.*)" bidness is saying grab everything between the "start title" and "end title" tags. That, if I'm not mistaken, is what's being stored as an element in the $info var. It's obviously a title for a story.
Now I'm assuming (hoping actually) somewhat that perhaps there is a place in the document that's very similar to what we have above. How do you, and in turn, your script, know when to start parsing for the information. Is there a place similar to the above.
Code: Select all
<!--- point ---->
point information here
<!--- end points --->
If it's something like the above; something where you know where the information is going to begin and end, then you can use ereg as I did above and use "(.*)" to grab all the data between those two points. Did you create this document that is going to be parsed? Was the document created in such a way to make it easy to be parsed?
This is the kind of thing that xml is great for. But the document needs to be an xml document. If it is by chance that, then it's even easier. Let me know.