In my database I am storing the title of posts and when I create the links on the page I put the title of the post as the title attribute.
Use htmlspecialchars to output your strings
htmlspecialchars
htmlspecialchars("I don't",ENT_QUOTES); // returns I don't
That will also take care of other HTML characters such as < & > as explained in the manual,
http://php.net/manual/en/function.htmlentities.php