最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php 批量替換html標(biāo)簽的實例代碼

 更新時間:2013年11月26日 09:47:30   作者:  
這篇文章主要是對php批量替換html標(biāo)簽的實例代碼進(jìn)行了詳細(xì)的介紹,需要的朋友可以過來參考下,希望對大家有所幫助

1.把html元素全部去掉,或者保留某幾個html標(biāo)簽

復(fù)制代碼 代碼如下:

<?php
$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);
echo "/n";

// Allow <p> and <a>
echo strip_tags($text, '<p><a>');
?>


結(jié)果為(去掉了注釋):

<blockquote>Test paragraph. Other text
<p>Test paragraph.</p> <a href="#fragment">Other text</a></blockquote>2.相反,只去掉某一個html標(biāo)簽

復(fù)制代碼 代碼如下:

<?php
function strip_only($str, $tags, $stripContent = false) {
    $content = '';
    if(!is_array($tags)) {
        $tags = (strpos($str, '>') !== false ? explode('>', str_replace('<', '', $tags)) : array($tags));
        if(end($tags) == '') array_pop($tags);
    }
    foreach($tags as $tag) {
        if ($stripContent)
             $content = '(.+</'.$tag.'[^>]*>|)';
         $str = preg_replace('#</?'.$tag.'[^>]*>'.$content.'#is', '', $str);
    }
    return $str;
}

$str = '<font color="red">red</font> text';
$tags = 'font';
$a = strip_only($str, $tags); // red text
$b = strip_only($str, $tags, true); // text
?>

相關(guān)文章

最新評論

扎兰屯市| 邛崃市| 苏州市| 沙坪坝区| 汉中市| 名山县| 苍溪县| 南漳县| 锡林郭勒盟| 漳州市| 临夏市| 越西县| 嘉义市| 天等县| 塔城市| 剑阁县| 新乐市| 柳江县| 南和县| 炉霍县| 黔西| 湘阴县| 新河县| 利辛县| 乃东县| 海兴县| 东丰县| 淮滨县| 攀枝花市| 刚察县| 东辽县| 灵石县| 磐石市| 嘉荫县| 铜梁县| 云浮市| 巴南区| 固原市| 成都市| 武城县| 遂昌县|