Re: Extract links from strings
| From: | Paul M Foster | Date: | Mon, 21 Sep 2009 16:56:43 +0000 |
| Subject: | Re: Extract links from strings | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-298237@lists.php.net to get a copy of this message | ||
On Mon, Sep 21, 2009 at 12:52:12PM -0300, Jônatas Zechim wrote:
> Hi there, i've the following strings:
>
> $string1 = 'Lorem ipsum dolor http://site.com sit
> amet';
> $string2 = 'Lorem ipsum dolor http://www.site.com/ sit
> amet';
> $string3 = 'Lorem ipsum dolor http://www.site.net sit
> amet';
>
> How can I extract the URL from these strings?
> They can be [http:// + url] or [www. + url].
>
Use the preg_match() function (see
http://us2.php.net/manual/en/function.preg-match.php
) and a good
regular expression from a place like http://www.regexlib.com/
.
Paul
--
Paul M. Foster