php - Truncate title to single line & container width

Is there a way to truncate a title to the container width? I'm able to do truncate a long title to one line using t

Is there a way to truncate a title to the container width? I'm able to do truncate a long title to one line using the code below, but that doesn't really work for mobile.

<h3>
    <?php
        $thetitle = $post->post_title;
        $getlength = strlen($thetitle);
        $thelength = 33;
        echo substr($thetitle, 0, $thelength);
        if ($getlength > $thelength) echo "...";
    ?>
</h3>

Is there a way to truncate a title to the container width? I'm able to do truncate a long title to one line using the code below, but that doesn't really work for mobile.

<h3>
    <?php
        $thetitle = $post->post_title;
        $getlength = strlen($thetitle);
        $thelength = 33;
        echo substr($thetitle, 0, $thelength);
        if ($getlength > $thelength) echo "...";
    ?>
</h3>
Share Improve this question asked Mar 1, 2014 at 2:15 vytflavytfla 1831 silver badge7 bronze badges 1
  • Not with PHP. PHP executes on teh server and has no idea how the page gets rendered. – s_ha_dum Commented Mar 1, 2014 at 3:54
Add a comment  | 

1 Answer 1

Reset to default 1

how about using CSS3's "text-overflow:ellipsis;" ?

doing so will make sure your title stays in a single line, trimming whatever crossed the container's width limit.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745622392a4636598.html

相关推荐

  • php - Truncate title to single line &amp; container width

    Is there a way to truncate a title to the container width? I'm able to do truncate a long title to one line using t

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信