Reputation: 6254
What I want actually, I have a title which length is not fixed so when I would like to show string text in table for title column, I would like to strip text with ... if text is bigger than column width..
so here is example:
Please advise.
Upvotes: 1
Views: 90
Reputation:
i dont know about ur column width but u can add limit for Title
$string = "sdsdddsddds";
$string = strip_tags($string);
if (strlen($string) > 5) //u can add ur limit of character here
{
$stringCut = substr($string, 0, 5); //u can add ur limit of character here
$string = substr($stringCut, 0, strrpos($stringCut, ' ')).'... <a href="/this/story">Read More</a>';
}
echo $stringCut."".$string;
Upvotes: 0
Reputation: 1101
You can substr your result so it will only show a part of the result. I made an example to show you how.
<?php
$yourstring = 'This is KC, THis is KC, This is KC';
$rest = substr($yourstring, 0, 15);
echo $rest;
Upvotes: 0
Reputation: 29932
You can't achieve such an effect with PHP, since you don't know how wide your table is depending on different client screen widths. You could do so if you know the font, the font size and the column width in pixel and even then it is still a lot of arithmetics.
But there is a CSS property that does what you want: text-overflow: ellipsis;
Using this property the content is clipped and optionally appended by an ellipsis (…) if the box is to narrow.
See: https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow (browser support at bottom)
Upvotes: 2