Posted By

wellynz on 09/08/10


Tagged

url php html ascii clean cleaner


Versions (?)

toAscii


 / Published in: PHP
 

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

Report this snippet  

You need to login to post a comment.