php获取html内的纯文本

function getplaintextintrofromhtml($html, $numchars) {

        // Remove the HTML tags
        $html = strip_tags($html);

        // Convert HTML entities to single characters
        $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');

        $html_len = mb_strlen($html,'UTF-8');
        // Make the string the desired number of characters
        // Note that substr is not good as it counts by bytes and not characters
        $html = mb_substr($html, 0, $numchars, 'UTF-8');

        // Add an elipsis
        
        if($html_len>$numchars)
        {
            $html .= "…";
        }
         
        return $html;

    }

猜你喜欢

转载自blog.csdn.net/hyb1234hi/article/details/83790947
今日推荐