RES: Extract links from strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I don't think so, but I've found this (from PT-BR LIST):

$string = 'Lorem ipsum dolor http://site.com sit amet lorem www.google.com
';

preg_match_all('!(?:http://|www)[^ ]*!',$string,$links);

print_r($links);

Zechim

-----Mensagem original-----
De: Mattias Thorslund [mailto:mattias@xxxxxxxxxxxx] 
Enviada em: segunda-feira, 21 de setembro de 2009 15:07
Para: 'PHP-General List'
Assunto: Re:  Extract links from strings

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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux