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?
This might be the shortest way to replace any non alphanumeric character with a single hyphen:
trim(preg_replace('/[^a-z0-9-]+/', '-', strtolower($str)), '-')