I have this and one problem is that if the http:// it does replace it, which is good.
But if they miss the // it adds the whole http:// again giving me something like http://http:
I need a good url to come out of this regardless what they forget so in the end result would be http://theurl

$url = (strstr($_POST["websiteurl"],"http://")!=""?"":"http://").$_POST["websiteurl"];

So please any help would be great

    when a person submits a url, and they forget to add the http:// or maybe they just forget to add the 2 //
    End result I need it to make sure it only has http:// before the posted url

      anyone have any idea on how to do this ?

        You could use a function ... for example:

        <?php
        function format_url($url){
        	if(substr($url, 0, 7) != 'http://'){
        		if(substr($url, 0, 5) == 'http:'){
        			return 'http://'.substr($url, 5);
        		} else {
        			return 'http://'.$url;
        		}
        	}
        	return $url;
        }
        ?>

        Of course, you could still have problems if the user made a different input error (eg. 'htp://'). You could extend the function to cover all possibilities, but there are quite a few to deal with!!

        Trouble is, in my experience, if a user can do something wrong, they will (eventually, at least). So, don't use a method like this in your app if the app depends on the user input being correct (or at least correctable).

        P.

          Do some URL validation. If it fails, output an error message and tell them to type a correct URL.

            Thats exactally what I did...

              Write a Reply...