Page 1 of 1

Regular expression help (again)

Posted: Tue Aug 17, 2004 3:22 pm
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.

Posted: Tue Aug 17, 2004 3:52 pm
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.

Posted: Tue Aug 17, 2004 4:52 pm
by fxchain
Works great now.
Thank you!