Home > Backend Development > PHP Tutorial > PHP HTML富文本遇到某些字眼截取

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

WBOY
Release: 2016-06-23 13:51:21
Original
1379 people have browsed it

/** * @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>
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template