Hi there folks!

I am in need to stripping all special characters from a string and this particular string has already been converted with htmlentities, so I am trying to use htmlspecialchars_decode to do so, but it's not removing them.

Here's my code:

				$spec_string .= $spec_entry['name'] .' '. $spec_entry['value'].' ';
				echo $spec_string;
				$spec_string = htmlspecialchars_decode($spec_string);
				echo $spec_string;

Which echoes:

Fits Schwim's ride
Fits Schwim's ride

and to the browser, still looks like a single-quote or apostrophe.

Can anyone tell me what I'm doing wrong? It's mucking up my search system and can't really ignore this particular issue.

Thanks for your time!

    Maybe try [man]html_entity_decode/man instead?

      You need to use ENT_QUOTES as the second parameter to get any of the html_____() functions to operate on single-quotes.

      Next, the htmlentities/htmlspecialchars functions are output functions and should only be used when you output data to the browser. Your code implies that you have used them on input data, before it got stored somewhere. This is incorrect and causes the exact problem you are having in trying to search, since you have stored altered data, not the actual data.

        Write a Reply...