php

Convert HTML entities back to characters – PHP

In this tutorial, we are going to see how to convert HTML entities back to characters in PHP. You can use PHP’s htmlspecialchars_decode() function to convert HTML entities such as &amp;, &lt;, &gt; etc., to normal characters (i.e. &, <,>).

htmlspecialchars_decode() function does the opposite of htmlspecialchars() function which converts HTML characters to HTML entities.
 

Convert HTML entities back to characters in PHP
$str = "Lorem ipsum &lt;span&gt;dolor& lt;/span&gt; sit &lt;b&gt;amet&lt;/b&gt;";

echo htmlspecialchars_decode($str);

Output:

Lorem ipsum <span>dolor</span> sit <b>amet</b>

 
[st_adsense] mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *