How do I sanitize title URIs with PHP?

前端 未结 4 1730
情书的邮戳
情书的邮戳 2020-12-20 04:14

I am programming a blog and I want the URIs to be the title like the question title here in stackoverflow or like wordpress.
What are the rules for sanitizing a URI?

4条回答
  •  一向
    一向 (楼主)
    2020-12-20 05:06

    This might be the shortest way to replace any non alphanumeric character with a single hyphen:

    trim(preg_replace('/[^a-z0-9-]+/', '-', strtolower($str)), '-')
    

提交回复
热议问题