REGEX Find and echo

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
jwalsh
Forum Contributor
Posts: 202
Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH

REGEX Find and echo

Post by jwalsh »

Playing around a bit with REGEX and CURL on my weekend off (thanks pilgrims), and I'm hoping someone can help me with this.

Code: Select all

$homepage = YU_LoadPage("index");

$totalfunds = preg_match ("/Your account currently has $(.*) dollars!/", $homepage, $price);

echo "TEST PRICE: " . $price[0];
YU_LoadPage returns the output from the CURL.

I just want to find the price on a page that says "Your account currently has $35.00 dollars!"

What am I missing?

Josh
User avatar
jwalsh
Forum Contributor
Posts: 202
Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH

Post by jwalsh »

I got it a little closer with this...

Code: Select all

preg_match ("/Your account currently has (.*) dollars/", $homepage, $price);
That finds the match, but returns more than the value I want, it returns almost everything after it. All I want is the value in the sentance.

Any help is much appreciated
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

What i like to use to help me with my regex is, regex coach, its a program that is downloadable, and you input your sentance, or what ever then you can test different things with it.
http://common-lisp.net/mailman/listinfo/regex-coach

Code: Select all

$totalfunds = preg_match ("/Your account currently has .((\d*).(\d*)) dollars/", $homepage, $price);
That should work with

Code: Select all

echo "TEST PRICE: " . $price[1];
Because 0 is the "Your account" part..

-NSF
Post Reply