String to Clean URL Generator


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



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

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.