RE: [PHP] Regex Help for URL's [ANSWER]
| From: | Robert Cummings | Date: | Tue, 16 May 2006 23:21:53 +0000 |
| Subject: | RE: [PHP] Regex Help for URL's [ANSWER] | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-236307@lists.php.net to get a copy of this message | ||
On Tue, 2006-05-16 at 18:49, Robert Samuel White wrote:
> In case any one is looking for a solution to a similar problem as me, here
> is the answer. I used the code from my original post as my guiding light,
> and with some experimentation, I figured it out.
>
> To get any URL, regardless of where it is located, use this:
>
> preg_match_all("#\'http://(.*)\'#U",
> $content, $matches);
>
> This match anything similar to:
>
> 'http://www.domain.com/dir/dir/file.txt?query=blah'
>
> This is useful, if for example, you have a tag like this one:
>
> <A HREF="javascript:void(0);" ONCLICK="javascript:window.open =
>
> 'http://www.domain.com/dir/dir/file.txt?query=blah';">
>
> Now, for tags which are in quotes, rather than single quotes, just use:
>
> preg_match_all("#\"http://(.*)\"#U",
> $content, $matches);
I'd roll those two into one expression:
preg_match_all("#(\"|')http://(.*)(\"|')#U",
$content, $matches);
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com
|
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'