Posted By

uberdragon on 04/02/11


Tagged


Versions (?)

PHP URI From String


 / Published in: PHP
 

converts @ to at and & to and removes anything that isn't alphanumeric replaces all spaces with - extra check to ensure there is no doubling up of --'s in final result

  1. function getURI($url) {
  2. $cleanURL = str_replace(" ",'-',ucwords(preg_replace('/[^a-zA-Z0-9 ]/', "", str_replace(array('&','@'),array('and','at'),trim($url)))));
  3. while (strpos($cleanURL,'--') > 0) { $cleanURL = str_replace('--','-',$cleanURL); } // get rid of any excess -'s
  4. return $cleanURL;
  5. }

Report this snippet  

You need to login to post a comment.