I'm looking to modify a PHP string so I can use it as an anchor tag.
I used the method found here: Remove all special characters from a string
It worked well to remove ampersands from my strings, but it doesn't seem to be removing or affecting the brackets or punctuation.
Here's what I'm currently using:
$name_clean = preg_replace('/ [^A-Za-z0-9\-]/', '', $name); // REMOVES SPECIAL CHARACTERS
$name_slug = str_replace(' ', '-', $name_clean); // REPLACES SPACES WITH DASHES IN TITLE
$link = strtolower( $name_slug ); // CREATES LOWERCASE SLUG VERSION OF TITLE_SLUG
My string (in this case $name) = St. John's (Newfoundland).
The output I get = #st.-john'snewfoundland)
I'd like to remove the periods, apostrophes and brackets altogether.
Any help would be greatly appreciated!