Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用只读php缩短文本帖子_Php_Text_Strlen - Fatal编程技术网

如何使用只读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 */

这里是PHP的新手,我如何使用PHP缩短博客文章的文本?到目前为止,这是我的代码,但它不工作,我不知道我需要从这里去哪里

 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()
你所说的缩短我博客文章的文本是什么意思?你的意思是去掉绳子的末端吗?或者寻找同义词并将单词合并在一起以缩短标题?或者是第三个解决方案?好了,这里有一个更新,伙计们,帖子现在缩短了,但我需要“阅读更多”作为完整帖子的链接,我该怎么做?将代码更新为我当前拥有的内容,然后您需要使用链接将
阅读更多内容->