PHP - Removing the effect of HTML tags in string - BUT displaying them as well?
Consider strip_tags()
.
strip_tags("<b>TEXT</b>");
Output:
TEXT
But what if i want to nullify the effect of the tags but display them as well?
Output:
<b>TEXT</b>
Would i have to use preg_replace()
? Or is the开发者_开发技巧re a more elegant solution available?
Thanks :D
You can HTML encode the string via htmlspecialchars:
htmlspecialchars("<b>TEXT</b>");
You can easily convert characters to their HTML entity using htmlspecialchars or htmlentities. Make sure you check the PHP manual to determine what is most appropriate to your data, as both functions operate slightly differently.
You can then reverse the encoding with htmlspecialchars_decode and html_entity_decode - again, check which is most appropriate for your data.
You could always just replace <
with <
and >
with >
, yeah?
You can use textarea tag as following:
<textarea rows="5" cols="20"><?php echo "<b>Text<b>"; ?></textarea>
精彩评论