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??

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.