Help with preg_match - really stuck :(

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
123promotion
Forum Newbie
Posts: 1
Joined: Sun May 16, 2004 12:33 pm

Help with preg_match - really stuck :(

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Re: Help with preg_match - really stuck :(

Post 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
}
Post Reply