Posted By

vonlof on 03/21/11


Tagged

url http link


Versions (?)

Check url for http


 / Published in: PHP
 

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

  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  

You need to login to post a comment.