Limiting Number Of Characters Displayed In Table Cell
I have a PHP loop that adds data into a table cell. However, I want to apply a static size to the table cell, so if more data is returned than can fit inside the cell I want the e
Solution 1:
if (strlen($str) > 100) $str = substr($str, 0, 100) . "...";
Solution 2:
You can use mb_strimwidth
printf('<td>%s</td>', mb_strimwidth($cellContent, 0, 100, '…'));
If you want to truncate with respect to word boundaries, see
You can also control content display with the CSS property text-overflow: ellipsis
Unfortunately, browser support varies.
Solution 3:
functionprint_dots($message, $length = 100) {
if(strlen($message) >= $length + 3) {
$message = substr($message, 0, $length) . '...';
}
echo$message;
}
print_dots($long_text);
Solution 4:
$table_cell_data = ""; // This would hold the data in the cell$cell_limit = 100; // This would be the limit of characters you wanted// Check if table cell data is greater than the limitif(strlen($table_cell_data) > $cell_limit) {
// this is to keep the character limit to 100 instead of 103. OPTIONAL$sub_string = $cell_limit - 3;
// Take the sub string and append the ...$table_cell_data = substr($table_cell_data,0,$sub_string)."...";
}
// Testing outputecho$table_cell_data."<br />\n";
Post a Comment for "Limiting Number Of Characters Displayed In Table Cell"