[RESOLVED] htmlspecialchars_decode is not decoding
Results 1 to 3 of 3

Thread: [RESOLVED] htmlspecialchars_decode is not decoding

  1. #1
    Join Date
    Oct 2016

    resolved [RESOLVED] htmlspecialchars_decode is not decoding

    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!

  2. #2
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Maybe try html_entity_decode() instead?
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Senior Member
    Join Date
    Apr 2016
    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.
    Programming should not be a painful activity. If you are experiencing pain while programming, you are probably doing something wrong.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts