php substr() function with utf-8 leaves � marks at the end

前端 未结 7 1332
野的像风
野的像风 2020-11-27 05:32

Here is simple code



        
相关标签:
7条回答
  • 2020-11-27 05:47

    I hope this solution help you as it helped me a lot.

    <?php
    if(mb_strlen($post->post_content,'UTF-8')>200){
        $content= str_replace('\n', '', mb_substr(strip_tags($post-> post_content), 
                              0, 200,'UTF-8'));
        echo $content.'…';
    }else{
        echo str_replace('\n', '', strip_tags($post->post_content));
    }
    ?>
    
    0 讨论(0)
提交回复
热议问题