Regular expression help (again)

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
fxchain
Forum Newbie
Posts: 9
Joined: Tue Dec 09, 2003 12:05 pm

Regular expression help (again)

Post by fxchain »

I am trying to extract a number out of a string.
I can't get the regular expression to work right....please help.

<?php
// Get a file into an array. In this example we'll go through HTTP to get
// the HTML source of a URL.
$lines = file('http://www.google.com/search?q=source');

$result = htmlspecialchars($lines[37]);

if (preg_match("/of about/ ([\d\,]+)", $result, $matches)) {
echo $matches[0];
} else {
echo "A match was not found.";
}
?>

In this example, I am trying to extract "of about 104,000,000" from google's search result page.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your delimiters are in the wrong place..

Code: Select all

/of\s+about\s+(&#1111;\d,]+)/
try that..

actually, that won't work.. looking at the page source:

Code: Select all

of about &lt;b&gt;105,000,000&lt;/b&gt;
try using [php_man]strip_tags[/php_man] instead of htmlspecialchars.
fxchain
Forum Newbie
Posts: 9
Joined: Tue Dec 09, 2003 12:05 pm

Post by fxchain »

Works great now.
Thank you!
Post Reply