PHP limit text string NOT including html tags?

后端 未结 5 2180
执笔经年
执笔经年 2021-01-05 03:34

Here\'s what\'s NOT working for me:

Jack and I love         


        
5条回答
  •  别那么骄傲
    2021-01-05 04:19

    You could try this, worked for me if no tags are in string $differ will have a value of 0 giving $stringsize your original value of 100

      Jack and I love him very much because he\'s my favorite dog in the whole wide world and nothing could make me not love him, I think.';
    
    $stringall=strlen($string);
    $striphtml = strip_tags($string);
    $stringnohtml=strlen(striphtml);
    $differ=($stringall-$stringnohtml);
    $stringsize=($differ + 100);
    $limited = substr($string, 0, $stringsize).'...';
    echo $limited;
    ?>
    

提交回复
热议问题