Search code examples
phphtmlspecial-characterscode-snippets

How to display the special characters with a combination of PHP code snippet in it


Am trying to display some random combination of special characters. Am already using UTF-8 encode. But sometimes due to the combination of <? the remaining characters followed by this combination are not displayed.

For example: For the below HTML code

<p>MRTest007865@%$%$%^$%><?Ñ£©¶</p>

I expect the output as:

MRTest007865@%$%$%^$%><?Ñ£©¶

But the actual output is:

MRTest007865@%$%$%^$%>

Solution

  • Try this using utf8_encode function

    echo utf8_encode("MRTest007865@%$%$%^$%><?Ñ£©¶");
    

    you can also try to use htmlspecialchars check the documentation here: https://www.php.net/manual/en/function.htmlspecialchars.php