Posted By

plesh on 07/12/11


Tagged

php pregreplace alpha-numeric


Versions (?)

Filter alphabetic characters only - PHP


 / Published in: PHP
 

Replace non alpha-numeric characters with PHP

  1. /**
  2.  * Used to give the full hyperlink for news/events items
  3.  *
  4.  * @param $type string - events/news
  5.  * @param $id int - ID of item for link
  6.  * @param $title string - item title for link to strip bad chars
  7.  **/
  8. public function seo_slug ( $type, $id, $title )
  9. {
  10. // strip bad chars
  11. $slug = trim(strtolower(preg_replace("/[^a-zA-Z0-9\s]/", "", $title)));
  12. $slug = str_replace(' ','-', $slug);
  13. $slug = str_replace(' ','-', $slug);
  14.  
  15. $url = '/'.$type.'/d/'.$id.'/'.$slug.'/';
  16.  
  17. return $url;
  18. }

Report this snippet  

You need to login to post a comment.