如何使用只读php缩短文本帖子
这里是PHP的新手,我如何使用PHP缩短博客文章的文本?到目前为止,这是我的代码,但它不工作,我不知道我需要从这里去哪里如何使用只读php缩短文本帖子,php,text,strlen,Php,Text,Strlen,这里是PHP的新手,我如何使用PHP缩短博客文章的文本?到目前为止,这是我的代码,但它不工作,我不知道我需要从这里去哪里 if ($stmt->prepare($sql)) { /*bind the parameter onto the query*/ $stmt->bind_param('i', $postid); /* execute statement */
if ($stmt->prepare($sql)) {
/*bind the parameter onto the query*/
$stmt->bind_param('i', $postid);
/* execute statement */
$stmt->execute();
/* bind result variables */
$stmt->bind_result($posttitle, $postdate, $postcontent);
/* fetch values */
if ($stmt->fetch()) {
if(strlen($postcontent)>10){
$postcontent=substr($postcontent,0,20).' Read more';
print ("<div class='blogposts'>$posttitle | $postdate</div><br/>\n $postcontent");
}
}
else{
print ("No category name is retrieved. <br/>");
}} else {
print ("query failed");
}
if($stmt->prepare($sql)){
/*将参数绑定到查询上*/
$stmt->bind_参数('i',$postid);
/*执行语句*/
$stmt->execute();
/*绑定结果变量*/
$stmt->bind_result($posttitle、$postdate、$postcontent);
/*获取值*/
如果($stmt->fetch()){
如果(strlen($postcontent)>10){
$postcontent=substr($postcontent,0,20)。'readmore';
打印($posttitle |$postdate
\n$postcontent);
}
}
否则{
打印(“未检索到类别名称。
”);
}}否则{
打印(“查询失败”);
}
不工作如何阅读更多
没有任何作用?引发错误?在打印了$postcontent
之后,您正在执行strlen()
/substr()
。尝试将if()
移动到print()之前的if()
你所说的缩短我博客文章的文本是什么意思?你的意思是去掉绳子的末端吗?或者寻找同义词并将单词合并在一起以缩短标题?或者是第三个解决方案?好了,这里有一个更新,伙计们,帖子现在缩短了,但我需要“阅读更多”作为完整帖子的链接,我该怎么做?将代码更新为我当前拥有的内容,然后您需要使用链接将阅读更多内容->