Jump to content

[SOLVED] making sure http:// is included.


whelpton

Recommended Posts

Im making a form processor that lets people submit links for use on a public profile.

 

I was wondering if there was any way of modifying this code:

$f = fopen("/home/alport/public_html/".$_SESSION['s_username']."/text/link1.txt", 'w');
fwrite($f, strip_tags($_POST['save']));
fclose($f);

To check for "http://" when it is submitted and if it is not there, then add it automatically?

 

Thanks alot

Link to comment
https://forums.phpfreaks.com/topic/149402-solved-making-sure-http-is-included/
Share on other sites

if(strpos('http://', $var_containing_url) === false) {

    //string does not contain http://

}

 

 

 

But, you will probably want to make sure that the URL starts with http:// in which case you could do if(!strpos(....) === 0) { /*doesn't start with it */ }

 

 

Is the URL in the middle of other content?  If so, you will have to use regular expressions.

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.