Forum Moderators: coopster

Message Too Old, No Replies

most reliable parsing condition

         

scorpion

5:04 am on Apr 30, 2003 (gmt 0)

10+ Year Member



I have a script that parses an HTML looking for a certain number string (unknown beforehand,e.g '5333') but its location in the HTML is known.

My question is this: No doubt this code can easily break, what is the most reliable (if you had to choose something) element to use as a condition for parsing out this string?

grahamstewart

10:10 am on Apr 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not sure I understand your question.

You know where this number appears in the HTML.
So are you looking for a function to extract it?

If the html looked like..

<span class="number">the number is 12345</span>

then the code I would use would look something like..

[pre]
$matches = array();
preg_match( '{<span\s*class\s*=\s*"number">the\s*number\s*is\s*([0-9]+)\s*</span>}i', $html, $matches);
if ( isset($matches[1]) )
echo "Number: ".$matches[1];
[/pre]

hope that helps - if not then give us some more details.