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 deko on 02/10/07 01:24

"BKDotCom" <bkfake-google@yahoo.com> wrote in message
news:1171054938.335019.14900@k78g2000cwa.googlegroups.com...
> 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 = 'A HREF="http://something.else.example.com/blah/?
> joe=bob"';
> if ( preg_match('|([^\s"\']*://[^\s"\']*)|',$long_string,$matches) )
> {
> $url = $matches[1]; // http://something.else.example.com/blah/?
> joe=bob
> $parts = parse_url($url);
> if ( preg_match('/(.+)\.\w+\.\w+/',$parts['host'],$matches) )
> echo $matches[1]; // something.else
> }

use regex to handle subdomains... I see!

but wouldn't the first few lines of my original code be a more efficient
starting point?

> elseif (eregi("http://", $agent))
> {
> $agent = stristr($agent, "http://");
> $agent = parse_url($agent);

//now use preg_match() to return everything beginning with a '.' up to
the next word boundary (?)

still testing...

 

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

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