Php 在描述后显示三点(…)?

Php 在描述后显示三点(…)?,php,Php,我使用这段php代码来显示带有描述的最新帖子。最大描述100字。如何在100字后显示3点(如:这是blablabla的内容…) 有人能帮帮我吗 这是我的php代码: <?php $rss = new DOMDocument(); $rss->load('http://domain.com/feed/'); $feed = array(); foreach ($rss->getElementsByTagName('item') as $node) { $item = array

我使用这段php代码来显示带有描述的最新帖子。最大描述100字。如何在100字后显示3点(如:这是blablabla的内容…

有人能帮帮我吗

这是我的php代码:

<?php
$rss = new DOMDocument();
$rss->load('http://domain.com/feed/');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
);
array_push($feed, $item);
}
$limit = 5;
for($x=0;$x<$limit;$x++) {
$title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
$link = $feed[$x]['link'];
$description = $feed[$x]['desc'];
$description = substr($description, 0, 138); 
$date = date('d F Y - H:m', strtotime($feed[$x]['date']));
echo '<li><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong>';
echo '<br><small>'.$date.'</small>';
echo '<br>'.$description.'</br></li>';
}
?>

如果我像这样查看您的代码,但这是计算每个符号,而不是单词:

if(strlen($description) > 138) {
    $description = substr($description, 0, 138).'&hellip;'; 
}
如果您想使用单词,请执行以下操作:

// put this function above your code....
function string_limit_words($string, $word_limit=100, $ending = '&hellip;') { 
    $words = explode(' ', $string); 
    if(count($words) > $word_limit) {
        return implode(' ', array_slice($words, 0, $word_limit)).$ending; 
    }
    return $string;
}

// and use it like this...
echo '<br>'.string_limit_words($description).'</br></li>';
//将此函数置于代码之上。。。。
函数string_limit_words($string,$word_limit=100,$ending='&hellip;'){
$words=explode(“”,$string);
如果(计数($words)>$word\u限制){
返回内爆(“”,数组_切片($words,0,$word_限制))。$end;
}
返回$string;
}
//像这样使用它。。。
回显“
”。字符串限制单词($description)。“
”;
刚好在第100个单词之后?谢谢米歇尔的帮助。描述后如何显示3点(…)??请帮助?
回显“
”。字符串限制单词($description)。“…
或者,您可以使用
&hellip天哪,我不知道“&hellip;”。谢谢,我现在就试试。@axel.michel哦,对不起,我完全错过了!