note 96684 deleted from function.htmlentities by danbrown

From: Date: Thu, 11 Mar 2010 13:53:44 +0000
Subject: note 96684 deleted from function.htmlentities by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-166913@lists.php.net to get a copy of this message
Note Submitter: sushant verma ---- i m trying to parse the html tags namely < > " ' and & into &lt; &gt; &quot &#039; and &amp; i m writing the following code and tried with some other codes also which are commented here, but what i got is: <?php function parse($code) { echo htmlspecialchars($code, ENT_COMPAT); echo "<br />"; //output: < > & \" \' echo htmlentities($code, ENT_QUOTES); echo "<br />"; //output: < > & \" \' $text = str_replace( array('>', '<', '\"', "\'"), array('&gt;', '&lt;', '&quot;', '&#039;'),$code); echo str_replace('&','&amp;',$text); //output: &lt; &gt; & &quot; &#039; echo "<br />"; $arr=array('>'=>'&gt;', '<'=>'&lt;', '\"'=>'&quot;', '&'=>'&amp;','\''=>'&#039;'); echo strtr( $code,$arr); //output: < > & " \' } $tag=$_POST['html_parse']; echo parse($tag); ?> plz help me to print "&amp;" on the browser for every '&" the sourse code of the browser says: <html> <body> &lt; &gt; &amp; \&quot; \'<br />&lt; &gt; &amp; \&quot; \&#039;<br />&amp;lt; &amp;gt; &amp; &amp;quot; &amp;#039;<br />&lt; &gt; &amp; &quot; \&#039; </body> </html> plz help me out

« previous php.notes (#166913) next »