PHP URI From String


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

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.