我有一个功能,但其他人可能会说,这不是一件好事,因为我还是擅长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