admin管理员组文章数量:1434956
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
1 Answer
Reset to default 1how 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.
本文标签: phpTruncate title to single line amp container width
版权声明:本文标题:php - Truncate title to single line & container width 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745622391a2666763.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论