I'm writing a system for articles. In mysql, each article has title and content.
the index page shows a link to all articles, and the href value is the title or the article, with some fixes. For example:
That's easy: in the index I'm using str_replace for replacing spaces to hyphen, and in the page shows the article (htaccess refers to this page) simply replacing hyphen to space, and showing the article with this title."first article" => <a href="first-article">first article</a>
"hello world article" => <a href="hello-world-article">hello world article</a>
My problem is that titles can include characters like "?", "!", ",", "-" and many more. Of course, I can link to the article without these characters, something like this:
But, I have no idea how I can convert first-article back to first - article? in the article page (in order to show the correct article)."first - article?" => <a href="first-article">first - article?</a>
Is there an elegant solution to this problem? I want to avoid adding another column to my database with the href-value.
Thanks a lot.