Reply to Re: How to add "http" to the beginning of bad links?

Your name:

Reply:


Posted by Rik on 05/15/06 20:10

NC wrote:
> laredotornado@zipmail.com wrote:
>>
>> I have a scalar variable, "$url" that may or not contain "http://"
>> in front of it. If it is not there, I'd like to add it.
>> Unfortunately, this code isn't working for me with PHP 4.
>>
>> if (strpos(strtolower($url), "http://") !=
>> 0) { $url = "http://$url";
>> } // if
>>
>> How can I correct?
>
> if (strpos(strtolower($url), "http://") !== false) {
> $url = "http://$url";
> }
>

It's just a pity for relative links, other protocols (https://, ftp://, even
mailto:, all extremely valid). Then again, that wasn't the op's question...

I'd:
if(preg_match('"^(https?://|ftp://|mailto:|\.{0,2}/|smb://|file://|s?news:|l
dap(i|s)?:|gopher:|nntp:|telnet:|mms:|ssh:)"si', $url)<1) $url =
'http://'.$url;

I'm still forgetting a lot of other possibilities though...

Grtz,
--
Rik Wasmus

[Back to original 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

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