note 96684 added to function.htmlentities

From: Date: Thu, 11 Mar 2010 13:52:21 +0000
Subject: note 96684 added to function.htmlentities
Groups: php.notes 
Request: Send a blank email to php-notes+get-166912@lists.php.net to get a copy of this message
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 ---- Server IP: 69.147.83.197 Probable Submitter: 121.242.88.23 ---- Manual Page -- http://www.php.net/manual/en/function.htmlentities.php Edit -- https://master.php.net/note/edit/96684 Del: integrated -- https://master.php.net/note/delete/96684/integrated Del: useless -- https://master.php.net/note/delete/96684/useless Del: bad code -- https://master.php.net/note/delete/96684/bad+code Del: spam -- https://master.php.net/note/delete/96684/spam Del: non-english -- https://master.php.net/note/delete/96684/non-english Del: in docs -- https://master.php.net/note/delete/96684/in+docs Del: other reasons-- https://master.php.net/note/delete/96684 Reject -- https://master.php.net/note/reject/96684 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#166912) next »