Jump to content

[SOLVED] super simple function not working right...


mrbuter

Recommended Posts

This is so weird....

 

check out this function:

 

function addhttp($url) {
	if (!strstr("http://", $url)) {
		$url = "http://".$url."";
	}
	return $url;
}

 

It's so easy....

 

It's meant to add an http:// prefix to a url if it does not already have one.

 

If I enter www.google.com into the function, it outputs as

 

http://www.google.com (correct!0

 

If I enter http://www.google.com into the function, it outputs as

 

http://http//www.google.com

 

Two things here:

 

1. why is it adding the prefix if it already has it? The code shouldn't let that happen...right?

2. Stranger still, not only does it ADD the prefix, but it proceeds to remove the colon from the original http:// which results in http://http// rather than http://http:// (which would still be wrong anyways)

 

 

Any ideas what on earth is going on??

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.