Check url for http


/ Published in: PHP
Save to your folder(s)

takes a url and appends http to it if http is not present


Copy this code and paste it in your HTML
  1. // takes a url and appends http to it if http is not present
  2. function check_http($link){
  3. $findme = 'http';
  4. $pos = strpos($link, $findme);
  5. // Note our use of ===. Simply == would not work as expected because the position of 'a' was the 0th (first) character.
  6. if ($pos === false) {
  7. //echo "The string '$findme' was not found in the string '$mystring'";
  8. $full_link = "http://".$link;
  9.  
  10. } else {
  11. //echo "The string '$findme' was found in the string '$mystring' and exists at position $pos";
  12. $full_link = $link;
  13. }
  14. return $full_link;
  15. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.