Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
jwalsh
Forum Contributor
Posts: 202 Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH
Post
by jwalsh » Fri Nov 25, 2005 5:45 pm
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
jwalsh
Forum Contributor
Posts: 202 Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH
Post
by jwalsh » Fri Nov 25, 2005 10:54 pm
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
Zoxive
Forum Regular
Posts: 974 Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan
Post
by Zoxive » Fri Nov 25, 2005 11:32 pm
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
Because 0 is the "Your account" part..
-NSF