PHP如何在不使用HTML标签的情况下进行回显 [英] PHP How to echo without HTML tags

查看:49
本文介绍了PHP如何在不使用HTML标签的情况下进行回显的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种系统,每个人都可以键入他想要的任何内容.不过,他们似乎也可以使用< img SRC =''......//> < a href =''...''</a> 等.

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.

您如何确切地防止这种情况发生?因此,举例来说,如果有人键入< h1> Hello</h1> ,则文本不会变大,但只会显示< h1> Hello</h1> .

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.

推荐答案

要使HTML显示为书面形式,您需要转义"特殊字符& ;,<和>使用 htmlspecialchars() .

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

或者,您可以使用 strip_tags()

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

这篇关于PHP如何在不使用HTML标签的情况下进行回显的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆