whelpton Posted March 14, 2009 Share Posted March 14, 2009 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 More sharing options...
corbin Posted March 14, 2009 Share Posted March 14, 2009 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. Link to comment https://forums.phpfreaks.com/topic/149402-solved-making-sure-http-is-included/#findComment-784677 Share on other sites More sharing options...
Daniel0 Posted March 14, 2009 Share Posted March 14, 2009 $url .= substr($url, 0, 7) != 'http://' ? 'http://' : null; Link to comment https://forums.phpfreaks.com/topic/149402-solved-making-sure-http-is-included/#findComment-784678 Share on other sites More sharing options...
whelpton Posted March 14, 2009 Author Share Posted March 14, 2009 Thanks for the two replies, but I am an absoloute beginner at php and I have no idea of how to integrate that into my existing code, can someone show me how to? Link to comment https://forums.phpfreaks.com/topic/149402-solved-making-sure-http-is-included/#findComment-784682 Share on other sites More sharing options...
Daniel0 Posted March 14, 2009 Share Posted March 14, 2009 Then you need to read through the Language Reference chapter of the manual. It's required reading for anyone. No excuse. Link to comment https://forums.phpfreaks.com/topic/149402-solved-making-sure-http-is-included/#findComment-784685 Share on other sites More sharing options...
whelpton Posted March 14, 2009 Author Share Posted March 14, 2009 Thanks Link to comment https://forums.phpfreaks.com/topic/149402-solved-making-sure-http-is-included/#findComment-784688 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.