Re: Extract links from strings

From: Date: Mon, 21 Sep 2009 18:06:58 +0000
Subject: Re: Extract links from strings
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-298240@lists.php.net to get a copy of this message
On Mon, 2009-09-21 at 11:06 -0700, Mattias Thorslund wrote: > 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]. > > > > Zechim > > Simple: > > function RemoveLorem($string) > { > return str_replace(array('Lorem ipsum dolor ', ' sit amet'), > '', > $string); > } > > $url1 = RemoveLorem($string1); > $url2 = RemoveLorem($string2); > $url3 = RemoveLorem($string3); > > Cheers :-) > > Mattias > Erm, I think the Lorem Ipsum was just filler text in this example, and may not actually occur in the final content ;) Thanks, Ash http://www.ashleysheridan.co.uk

« previous php.general (#298240) next »