Posted By

traeregan on 08/17/09


Tagged

url clean


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

umang_nine


String to Clean URL Generator


 / Published in: PHP
 

URL: http://cubiq.org/the-perfect-php-clean-url-generator/12

  1. setlocale(LC_ALL, 'en_US.UTF8');
  2. function toAscii($str, $replace=array(), $delimiter='-') {
  3. if( !empty($replace) ) {
  4. $str = str_replace((array)$replace, ' ', $str);
  5. }
  6.  
  7. $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
  8. $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
  9. $clean = strtolower(trim($clean, '-'));
  10. $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
  11.  
  12. return $clean;
  13. }

Report this snippet  

You need to login to post a comment.