php - 显示 php mysql 大段落的前 3 行

标签 php mysql

我正在使用 PHP 和 MySQL 从数据库获取数据。我在数据库中有一个描述字段。在描述字段中包含大段。

例如:(在数据库描述字段中包含此段)

The ‘Fox and the Grapes’ is often cited as an example for cognitive dissonance: the discomfort people experience when their beliefs/actions are at odds with other beliefs/actions. In the story, the fox sees some grapes on a vine and wants to eat them. He tries to jump up, but cannot reach them because they are too high. When he realizes he will not be able to eat any grapes, the fox becomes disdainful; he tells himself that those grapes were sour and not worthy of desire anyway.

现在我只想要这一段的前三行

The ‘Fox and the Grapes’ is often cited as an example for cognitive dissonance: the discomfort people experience when their beliefs/actions are at odds with other beliefs/actions.

最佳答案

您可以使用前 100200 字符来代替前三行,以满足您的要求并显示 ...more 按钮获取整个文本。为此,您必须获取整个文本的前 100 或 200 个字符,然后显示 ...more 按钮。

要获取字符串的前 100 个字符,请确保不要破坏单词,例如:

$pos=strpos($content, ' ', 200);
echo substr($content,0,$pos ); 

Example

关于php - 显示 php mysql 大段落的前 3 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44427131/

相关文章:

php - 函数调用中命名参数和参数解包生成的错误不会在 PHP-8 中抛出 ErrorException

php - ubuntu系统启动添加ssh

php - 我的程序的正确流程是什么?

php - 将今天的日期添加到 mysql 插入

mysql - 五个表均来自第一个表,如果存在,则将其他表与第五个表中的最大值连接起来

php - 在php mysql查询中添加javascript

mysql - 获取查询中包含 LIMIT 的所有结果的计数

php - 使用 PHP 进行霍夫变换

PHP 显示最流行的标签

php - 反转 switch case 语句(直到为真)