Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP How to echo without HTML tags

I have a sort of system where everybody can type whatever he wants. Though, they can also seem to use tags like <img SRC="..."/> , <a href="..."></a> etc.

How could you exactly prevent this? So as example, if someone types in <h1>Hello</h1> the text won't get big, but it would just show <h1>Hello</h1>.

If it's not possible to do this please give me an alternative.

like image 868
user1663544 Avatar asked May 18 '26 20:05

user1663544


2 Answers

To make the HTML display as written, you need to "escape" the special characters &, < and > using htmlspecialchars().

Alternatively, you could remove all the tags and display the remaining text using strip_tags()

like image 132
IMSoP Avatar answered May 21 '26 12:05

IMSoP


You may try :

echo htmlspecialchars('<a href="http://www.google.com">Google</a>');

More info here

like image 29
Alain Tiemblo Avatar answered May 21 '26 11:05

Alain Tiemblo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!