Filter alphabetic characters only - PHP


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

Replace non alpha-numeric characters with PHP


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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.