php去掉html标签的方法:1、通过“function strip($str){...}”方法删除HTMl标签;2、通过“strip_tags”函数去除HTML标签;3、通过strtr函数转换字符串中特定的字符。
推荐:《PHP视频教程》
PHP删除HTMl标签的三种解决方法
方法1:
直接取出想要取出的标记
代码如下:
","",$str); //$str=htmlspecialchars($str); return strip_tags($str); } ?>
方法2.
PHP 中有个 strip_tags 函数可以方便地去除 HTML 标签。
echo strip_tags(“Hello World”); // 去除 HTML、XML 以及 PHP 的标签。
对于非标准的 HTML 代码也能正确的去除:
echo strip_tags(“\\”>cftea”); //输出 cftea
在PHP中可以使用strip_tags函数去除HTML标签,看下面示例:
代码如下:
dreamdu.com'; echo(htmlspecialchars($str).”
”); echo(strip_tags($str)); ?>
方法3.
strtr() 函数转换字符串中特定的字符。
语法
strtr(string,from,to)
或者
strtr(string,array)
参数
string1 必需。规定要转换的字符串。
from 必需(除非使用数组)。规定要改变的字符。
to 必需(除非使用数组)。规定要改变为的字符。
array 必需(除非使用 from 和 to)。一个数组,其中的键是原始字符,值是目标字符。
例子1:
代码如下:
例子2:
代码如下:
"Hi", "world" => "earth"); echo strtr("Hello world",$arr); ?>
The above is the detailed content of How to remove html in php. For more information, please follow other related articles on the PHP Chinese website!