note 61566 added to function.preg-match-all
| From: | bgamrat at wirehopper dot com | Date: | Tue, 07 Feb 2006 03:54:25 +0000 |
| Subject: | note 61566 added to function.preg-match-all | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-103151@lists.php.net to get a copy of this message | ||
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. :)
----
Server IP: 216.194.113.175
Probable Submitter: 68.170.141.127
----
Manual Page -- http://www.php.net/manual/en/function.preg-match-all.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61566
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61566&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61566&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61566&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61566&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61566&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61566&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61566&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61566&report=yes
Search -- http://master.php.net/manage/user-notes.php