Limiting number of characters displayed in table cell

后端 未结 4 340
渐次进展
渐次进展 2021-01-27 11:48

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 th

4条回答
  •  一整个雨季
    2021-01-27 12:16

    $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 limit
    if(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 output
    echo $table_cell_data."
    \n";

提交回复
热议问题