You are here: Re: Best way to extract URL from random string? « PHP Programming Language « IT news, forums, messages
Re: Best way to extract URL from random string?

Posted by Rik on 02/09/07 21:14

On Fri, 09 Feb 2007 22:02:18 +0100, BKDotCom <bkfake-google@yahoo.com> =

wrote:

> On Feb 9, 2:15 pm, "deko" <d...@nospam.com> wrote:
>
>> Are there any PHP functions that will help here? How to handle sub =

>> domains?
>> International domains?
>>
>> Thanks in advance.
>
> well, you found parse_url
> you might want to use regular expressions as well
>
> $long_string =3D 'A HREF=3D"http://something.else.example.com/blah/?
> joe=3Dbob"';
> if ( preg_match('|([^\s"\']*://[^\s"\']*)|',$long_string,$matches) )

Afaik protocols can only be a-z+, you don't have to capture the entire =

match, and the url should have at least one character, so a little =

optimised it would be:

'|[a-z]+://[^\s"\']+|i'


> {
> $url =3D $matches[1]; // http://something.else.example.com/blah/?
> joe=3Dbob

$url =3D $matches[0];

-- =

Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация