Posted By

iloveitaly on 06/05/09


Tagged

fix valid url http format check uri standardize


Versions (?)

Standardize URL String


 / Published in: PHP
 

this function processes a URL that 'should' be a full url (i.e. http://something.com/dfsdfs/) and makes sure it contains http:// for easy inclusion as a link into a href attribute

  1. // this function processes a URL that 'should' be a full url (http://something.com/dfsdfs/)
  2. // and makes sure it contains the correct format to be included into a href attribute
  3. function processURLString($urlString) {
  4. $urlString = trim($urlString);
  5.  
  6. if($urlString) {
  7. $urlString = preg_replace('/https?:\/\//', '', $urlString);
  8. $urlString = trim($urlString);
  9. $urlString = 'http://'.$urlString;
  10. }
  11.  
  12. return $urlString;
  13. }

Report this snippet  

You need to login to post a comment.