有没有办法限制echo $row->编码器中的变量


Is there any way to limit characters in echo $row-> variable in codeigniter

我目前正在开发一个CMS,并希望添加限制文本摘录的行长度的功能。假设我想控制文本的显示,并通过控制显示的文本行数来确保所有块的高度相同。我使用每个显示收件箱功能消息数据。在消息部分,它显示了完整的消息,我想将其限制为30

<?php
if(isset($records)) :
foreach($records as $row) :
?>
                <tr >
                    <td class="right"><?php  echo $row->contactus_name; ?></td>
                    <td class="right"><?php  echo $row->contactus_email; ?></td>
                    <td class="right"><?php  echo $row->contactus_phone; ?></td>
                    <td class="right tertiary-text-secondary text-justify"><?php  echo $row->contactus_comment; ?></td>
                </tr>
            <?php  endforeach; ?>
            </tbody>
            <tfoot></tfoot>
        </table>
        <?php else : ?>
            <p>No records</p>
        <?php  endif; ?>

如果您在控制器中包含text helper:

$this->load->helper('text');

或在autoload.php中:

$autoload['helper'] = array('url', 'form', 'html', 'text');

您可以使用word_limiter()

来自文档:

$string = "Here is a nice text string consisting of eleven words.";
$string = word_limiter($string, 4);
// Returns: Here is a nice…

也有同样工作方式的character_limiter()。同样,从文档中:

$string = "Here is a nice text string consisting of eleven words.";
$string = character_limiter($string, 20);
// Returns: Here is a nice text string…

//IN CONTROLLER

$this->load->helper('text');
<?php echo word_limiter($row->contactus_comment,30); ?>