note 61566 deleted from function.preg-match-all by colder
| From: | colder@php.net | Date: | Mon, 16 Apr 2007 17:01:23 +0000 |
| Subject: | note 61566 deleted from function.preg-match-all by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-125467@lists.php.net to get a copy of this message | ||
Note Submitter: bgamrat at wirehopper dot com
----
I used these regular expressions to get the references from a page. The function run_preg lists
the references found.
$url = "http://test.com";
$text=@file_get_contents($url);
if ($text)
{
$src_href_url=run_preg($text,
"/(?:(?:src|href|url)\\s*[=\\(]\\s*[\\"'`])".
"([\\+\\w:?=@&\\/#._;-]+)(?:[\\s\\"'`])/i");
$windows=run_preg($text,
"/(?:window.open\\s*\\(\\s*[\\w-]*\\s*[,]\\s*[\\"`'])".
"([\\+\\w:?=@&\\/#._;-]*)(?:[\\"'`]\\s*)/i");
}
function run_preg($text,$pattern) {
preg_match_all ($pattern, $text, $matches);
if (count($matches)>0)
if (count($matches[1])>0)
foreach ($matches[1] as $k => $v)
echo "$k: $v\\n";
return (is_array($matches)) ? $matches[1]:FALSE;
}
Thanks to http://us2.php.net/manual/en/function.preg-match.php#58505
for giving me a good starting point.
Hope others find this useful. :)