So, I've seen a ton of "solutions" on this site, but none of them seem to work fully for me. I would like to strip all punctuation from a post name so that the system can dynamically create urls for each post. I found an article by David Walsh that provides a step by step tutorial on how this can be achieved. However, not everything gets stripped. Here is a link to the article (just in case): http://davidwalsh.name/php-seo.
Here's the code I've altered to remove all punctuation:
$return = trim(preg_replace('/[^a-z0-9]+/i'," ", strtolower($post_name)));
Here's an example post name: Testing's, this & more!
Results when I echo the url: testing-039-s-this-amp-more.php
I'm not sure why it's keeping the html code for the ampersand and the single quote. Any ideas?!?
Looks like the data is run through
htmlspecialchars()
orhtmlentities()
somewhere. Undo that withhtmlspecialchars_decode()
orhtml_entity_decode()
first:@see