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.
Regular expression help (again)
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
your delimiters are in the wrong place.. try that..
actually, that won't work.. looking at the page source:
try using [php_man]strip_tags[/php_man] instead of htmlspecialchars.
Code: Select all
/of\s+about\s+(ї\d,]+)/actually, that won't work.. looking at the page source:
Code: Select all
of about <b>105,000,000</b>