Page 1 of 1

REGEX Find and echo

Posted: Fri Nov 25, 2005 5:45 pm
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

Posted: Fri Nov 25, 2005 10:54 pm
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

Posted: Fri Nov 25, 2005 11:32 pm
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