我正在为我的网站使用CodeIgniter。我还在我的网站上使用tumblr API来显示发布的新闻。使用截断字符串替换数组中的字符串
由于显示整个文本有点太多,我想截断正文副本为150个字符,我通过使用CI的character_limiter
函数来完成此操作。
的代码是跟随我的“家”控制器:
public function index() {
//Title for home page
$data['title'] = "Home - Welcome";
// Obtain an array of posts from the specified blog
// See the config file for a list of settings available
$tumblr_posts = $this->tumblr->read_posts();
foreach($tumblr_posts as $tumblr_post) {
$tumblr_post['body'] = character_limiter($tumblr_post['body'], 150);
}
// Output the posts
$data['tumblr_posts'] = $tumblr_posts;
// Load the template from the views directory
$this->layout->view('home', $data);
}
的问题是,当我赞同它在我的视图页面上$tumblr_post['body']
不会缩短。像上面这样做在Asp.net(C#)中工作,但它似乎无法在PHP中工作,任何人都知道为什么以及如何解决它或有其他方法吗?
是否包含文字帮手..? –
我鼓励你在视图中做这个,而不是控制器。 –
请发布函数character_limiter()的代码? – elias