[英]Add … after x characters if string too long in grocery crud in CI
我在MySQL數據庫中有一個description字段,我在兩個不同的頁面上訪問數據庫,一個頁面顯示整個字段,但在另一個頁面上,我只想顯示前50個字符。
如果description字段中的字符串少於50個字符,則不會顯示...,但是如果不是,則在前50個字符后顯示...。
希望這個能對您有所幫助 :
您可以使用codeigniter
text
幫助器完成此任務 ,然后在autoload.php
加載文本幫助autoload.php
$autoload['helper'] = array('text');
像這樣使用word_limiter()
$string = "Here is a nice text string consisting of eleven words.";
$string = word_limiter($string, 4,'...');
或像這樣使用character_limiter()
$string = "Here is a nice text string consisting of eleven words. and so on";
$string = character_limiter($string, 50,'...');
在你的情況下使用character_limiter()
供參考: https : //www.codeigniter.com/user_guide/helpers/text_helper.html
您可以使用$this->load->helper('text');
這用於設置字符限制,也可以使用substr
函數進行設置。
$this->load->helper('text');
$string = "Here is a nice text string consisting of eleven words.";
echo $string = character_limiter($string, 20); // using text helper in codeigniter
echo substr($string, 0,10); // using substr . start from 0 and end on 10
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.