skip to Main Content

I have following string:

ab"wefdty?'aaavvv

After submitting the data it shows like this :

ab'wefdty?"aaavvv

I tried with htmlspecialCharacters, htmlentities but it won’t work. How should I get the original text back?

2

Answers


  1. You should use the html_entity_decode function :

    https://www.php.net/manual/en/function.html-entity-decode.php

    echo html_entity_decode("ab'wefdty?"aaavvv");
    
    Login or Signup to reply.
  2. You can use following PHP functions as both are valid approaches:

    html_entity_decode()
    htmlspecialchars_decode()
    

    But htmlspecialchars_decode() is limited as it only decodes some characters:
    (&, " (double quote), ‘< (less than), and ‘ (greater than)).

    If your encoded string includes other HTML entities, html_entity_decode() would be more comprehensive.

    To decode entities back to their original characters in PHP, you can do it in following way:

    $encodedString = 'ab&#039;wefdty?&quot;aaavvv';
    $decodedString = html_entity_decode($encodedString, ENT_QUOTES | ENT_HTML401, 'UTF-8');
    echo $decodedString;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search