我正在使用 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.
最佳答案
您可以使用前 100
或 200
字符来代替前三行,以满足您的要求并显示 ...
或more
按钮获取整个文本。为此,您必须获取整个文本的前 100 或 200 个字符,然后显示 ...
或 more
按钮。
要获取字符串的前 100 个字符,请确保不要破坏单词,例如:
$pos=strpos($content, ' ', 200);
echo substr($content,0,$pos );
关于php - 显示 php mysql 大段落的前 3 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44427131/