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? Is there an already made code in PHP that does this?
Thanks in advance, Omer
This might be the shortest way to replace any non alphanumeric character with a single hyphen:
trim(preg_replace('/[^a-z0-9-]+/', '-', strtolower($str)), '-')
2.1m questions
2.1m answers
60 comments
57.0k users