仅筛选字母字符-PHP

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了仅筛选字母字符-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-9s]/", "", $title)));
  12. $slug = str_replace(' ','-', $slug);
  13. $slug = str_replace(' ','-', $slug);
  14.  
  15. $url = '/'.$type.'/d/'.$id.'/'.$slug.'/';
  16.  
  17. return $url;
  18. }

以上是关于仅筛选字母字符-PHP的主要内容,如果未能解决你的问题,请参考以下文章