我有一個功能,但其他人可能會說,這不是一件好事,因爲我還是擅長PHP太(TIPS歡迎的人),但是這會給你你在找什麼,它可能需要更好的編碼,如果任何人都有建議。
function Short($text, $length, $url, $more){
$short = mb_substr($text, 0, $length);
if($short != $text) {
$lastspace = strrpos($short, ' ');
$short = substr($short , 0, $lastspace);
if(!$more){
$more = "Read Full Post";
} // end if more is blank
$short .= "...[<a href='$url'>$more</a>]";
} // end if content != short
$short = str_replace("’","'", $short);
$short = stripslashes($short);
$short = nl2br($short);
} // end short function
使用:
說你的文章內容是變量$內容
function($content, "35", "http://domain.com/article_post", "Read Full Story");
echo $short;
同樣,你可以調整函數刪除$ url和$多從它,只是在...結尾處有...的摘錄。
什麼是你的問題,標點符號和數字?你想知道如何只顯示35條文章的文字? –
是的,我想知道如何只顯示文章的35個字。 – user1167384
[如何在PHP中使用substr()捕獲完整單詞,限制單詞?](http://stackoverflow.com/questions/3538130/how-to-capture-complete-words-using-substr-in -php-limit-by-word) – rdlowrey