How to add "http" to the beginning of bad links?

How to add "http" to the beginning of bad links?

Post by laredotorn » Wed, 17 May 2006 00:14:11


Hi,

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?

Thanks, - Dave
 
 
 

How to add "http" to the beginning of bad links?

Post by NC » Wed, 17 May 2006 00:41:38


if (strpos(strtolower($url), "http://") !== false) {
$url = "http://$url";
}

Read the Manual, it's all there:

http://www.yqcomputer.com/

Cheers,
NC

 
 
 

How to add "http" to the beginning of bad links?

Post by Rik » Wed, 17 May 2006 02:10:11


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:

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
 
 
 

How to add "http" to the beginning of bad links?

Post by John Dunlo » Wed, 17 May 2006 02:34:15

Rik:



Forget about particular schemes and match scheme names (plus colon)
in general:

`^[a-z][a-z\d+.-]+:`i

http://www.yqcomputer.com/ :3.1

--
Jock