Page 1 of 1

Help with preg_match - really stuck :(

Posted: Sun May 16, 2004 12:33 pm
by 123promotion
Hi

I am really stuck with preg_match to retreive a value and then use it to be calculated etc.

Here is my code:

preg_match("/<font face=\"Arial,sans-serif\" size=2 color=E8E8E8>(.+)<\/td>/is",$line,$matches); echo $matches[1];

This grabs the number within (.+) ok but sometimes this will be text. How can i ignore occurrences that contain text?

also, i want to use $matches[1] in a calculation but im having no luck - is it the [1] that is causing the problem.

eg i am trying $variable = $matches[1] + $matches[1];

....but no joy

please excuse me, because as you can tell, ima relative noob :(

i would be grateful if anyone could help?

Re: Help with preg_match - really stuck :(

Posted: Sun May 16, 2004 12:43 pm
by feyd
123promotion wrote::snip:
preg_match("/<font face="Arial,sans-serif" size=2 color=E8E8E8>(.+)<\/td>/is",$line,$matches); echo $matches[1];

This grabs the number within (.+) ok but sometimes this will be text. How can i ignore occurrences that contain text?

Code: Select all

preg_match("/<font face="Arial,sans-serif" size=2 color=E8E8E8>([0-9]+)<\/td>/is",$line,$matches);
also, i want to use $matches[1] in a calculation but im having no luck - is it the [1] that is causing the problem.
could always do something like this instead:

Code: Select all

$num = preg_replace("/<font face="Arial,sans-serif" size=2 color=E8E8E8>([0-9]+)<\/td>/is","\\1",$line);
if(!empty($num))
{ // you got a number in thar
}