首页  >  文章  >  后端开发  >  PHP HTML富文本遇到某些字眼截取

PHP HTML富文本遇到某些字眼截取

WBOY
WBOY原创
2016-06-23 13:51:211360浏览

/** * @author      default7<default7> * @description 裁剪HTML,当他遇到某段文字的时候 * * @param        $htmlContent * @param string $meetStr * * @return string */function cutHtmlWhenMeet($htmlContent, $meetStr = ''){    if (!empty($meetStr)) {        $posMeet = mb_strpos($htmlContent, $meetStr, null, 'UTF-8');        if ($posMeet !== false) {            $htmlEnd = mb_substr($htmlContent, 0, $posMeet, 'UTF-8');            $posEnd = mb_strrpos($htmlEnd, '', null, 'UTF-8') + 3;            while (true) {                $posEnd++;                $tmp = mb_substr($htmlEnd, $posEnd, null, 'UTF-8');                if (!trim(strip_tags($tmp)) || $posEnd >= $posMeet) {                    break;                }            }            $htmlContent = mb_substr($htmlContent, 0, $posEnd, 'UTF-8');        }    }    return $htmlContent;}</default7>

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn