国产欧美日韩第一页|日本一二三不卡视频|在线精品小视频,亚洲第一免费播放区,metcn人体亚洲一区,亚洲精品午夜视频

PHP清除html標簽、除空格和換行

2019-01-13 14:21:50 9399

方法一,strip_tags()剝?nèi)プ址械?HTML 標簽:

1
2
3
4
<?php
echo strip_tags("Hello <b>world!</b>");
//運行結(jié)果:Hello world!
?>


方法二,自定義函數(shù)去除

1
2
3
4
5
6
7
8
9
10
function cutstr_html($string, $sublen){
    $string = strip_tags($string);
    $string = preg_replace ('/\n/is', '', $string);
    $string = preg_replace ('/ | /is', '', $string);
    $string = preg_replace ('/&nbsp;/is', '', $string);
    preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/", $string, $t_string);
    if(count($t_string[0]) - 0 > $sublen) $string = join('', array_slice($t_string[0], 0, $sublen))."…";
    else $string = join('', array_slice($t_string[0], 0, $sublen));
    return $string;
}


提交成功!非常感謝您的反饋,我們會繼續(xù)努力做到更好!

這條文檔是否有幫助解決問題?

非常抱歉未能幫助到您。為了給您提供更好的服務,我們很需要您進一步的反饋信息:

在文檔使用中是否遇到以下問題: