Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 删除包含内部内容的所有标记_Php_Html - Fatal编程技术网

Php 删除包含内部内容的所有标记

Php 删除包含内部内容的所有标记,php,html,Php,Html,我想删除所有具有内部内容的标记 我正在使用以下函数 function strip_tags_content($text, $tags = '', $invert = FALSE) { preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags); $tags = array_unique($tags[1]); if (is_array($tags) AND count($tags) >

我想删除所有具有内部内容的标记

我正在使用以下函数

function strip_tags_content($text, $tags = '', $invert = FALSE) {

    preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
    $tags = array_unique($tags[1]);

    if (is_array($tags) AND count($tags) > 0) {
        if ($invert == FALSE) {
            return preg_replace('@<(?!(?:' . implode('|', $tags) . ')\b)(\w+)\b.*?>.*?</\1>@si', '', $text);
        } else {
            return preg_replace('@<(' . implode('|', $tags) . ')\b.*?>.*?</\1>@si', '', $text);
        }
    } elseif ($invert == FALSE) {
        return preg_replace('@<(\w+)\b.*?>.*?</\1>@si', '', $text);
    }
    return $text;
}
function strip\u tags\u content($text,$tags='',$invert=FALSE){
preg_match_all('//si',trim($tags),$tags);
$tags=array_unique($tags[1]);
如果(是_数组($tags)和计数($tags)>0){
如果($invert==FALSE){
返回preg_replace('@.*.@si','.$text);
}否则{
返回preg_replace('@.*.@si','.$text);
}
}elseif($invert==FALSE){
返回preg_replace('@.*.@si','.$text);
}
返回$text;
}
但我仍然得到了以下结果

<p><span style="color: rgb(38, 38, 38); font-family: arial, helvetica, sans-serif; fon...

您可以使用
PHP的
内置函数
strip\u标签

$striped_string = strip_tags($your_html_string);
注意:您还可以选择将某些标记作为第二个参数传递,以确保不会剥离这些标记


看看测试字符串在哪里?你能更清楚的看到PHP标签吗?我没有看到任何PHP…下一代Escalade和Escalade ESV。最受期待的一代凯迪拉克皇冠上的珠宝的到来仅仅值得一次介绍,还是更值得一次庆祝

这是我的字符串。我想从中删除所有html标记。utf8_substr(strip_标记(html_entity_decode($text,ENT_QUOTES,'UTF-8'))0,150为我工作。感谢大家花时间:)这不会删除标记内的内容。。最初的问题不是关于删除所有具有内部内容的标记吗?