Regular expression help (again)
Posted: Tue Aug 17, 2004 3:22 pm
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.
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.