php去掉字段文本的所有html标签

方法1:php内建函数 strip_tags()除去HTML标签

<?php
    header("content-type:text/html;charset=utf-8");
 
    function strip_html_tags($str){
        $pattern = '/<("[^"]*"|\'[^\']\*\'|[^>"\'])*>/';
        return preg_replace($pattern,'',$str);
    }
 
    // 实例
    $html = '<p id="">ddddd<br /></p>';
    echo strip_tags($html);
    echo "\n";
 
    $html = '<p id=">">bb<br />aaa<br /></p>';
    echo stripl_tags($html);
?>

方法2:利用正则

如:

<?php
    header("content-type:text/html;charset=utf-8");
 
    function strip_html_tags($str){
        $pattern = '/<("[^"]*"|\'[^\']\*\'|[^>"\'])*>/';
        return preg_replace($pattern,'',$str);
    }
 
    // 实例
    $html = '<p id="">ddddd<br /></p>';
    echo strip_html_tags($html);
    echo "\n";
 
    $html = '<p id=">">bb<br />aaa<br /></p>';
    echo strip_html_tags($html);
?>
微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_55204.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?