TEXT"); Conclusio...">

PHP - Removing the effect of HTML tags in a string - BUT also displaying them?

Consider strip_tags().

strip_tags("<b>TEXT</b>");

Conclusion:

TEXT

But what if I want to nullify the effect of tags, but showing them?

Conclusion:

<b> TEXT </b>

Should i use preg_replace()? Or is there a more elegant solution?

Thanks: D

+3
source share
3 answers

You can encode HTML through htmlspecialchars :

htmlspecialchars("<b>TEXT</b>");
+10
source

You can always just replace <with &lt;and >with &gt;, yes?

+1
source

Source: https://habr.com/ru/post/1744223/


All Articles