Return to Snippet

Revision: 43886
at April 2, 2011 02:39 by uberdragon


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

Revision: 43885
at April 2, 2011 02:16 by uberdragon


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

Initial URL

                                

Initial Description
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

Initial Title
PHP URI From String

Initial Tags

                                

Initial Language
PHP