note 96684 deleted from function.htmlentities by danbrown
| From: | danbrown@php.net | 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
< > " ' and &
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('>', '<', '"',
'''),$code);
echo str_replace('&','&',$text);
//output: < > & " '
echo "<br />";
$arr=array('>'=>'>', '<'=>'<',
'\"'=>'"',
'&'=>'&','\''=>''');
echo strtr( $code,$arr);
//output: < > & " \'
}
$tag=$_POST['html_parse'];
echo parse($tag);
?>
plz help me to print "&" on the browser for every '&"
the sourse code of the browser says:
<html>
<body>
<
>
&
\"
\'<br /><
>
&
\"
\'<br />&lt;
&gt;
&
&quot;
&#039;<br /><
>
&
"
\'
</body>
</html>
plz help me out