Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.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 如何从mysql中选择字符串的几个字符_Php_Mysql_String_Codeigniter_Truncate - Fatal编程技术网

Php 如何从mysql中选择字符串的几个字符

Php 如何从mysql中选择字符串的几个字符,php,mysql,string,codeigniter,truncate,Php,Mysql,String,Codeigniter,Truncate,我正在尝试实现各种文章的预览,预览应该是整篇文章的一小部分,以给读者和内容的想法 我目前的解决方案是将所有内容作为文本加载,并以最大宽度为300px的div显示,并隐藏溢出。虽然这确实有效,但似乎不是最好的解决方案 我认为使用mysql选择部分内容可能是一种选择。我应该如何获得预览,我应该只获得N个字符,还是MYSQL有更多针对这种行为的定制功能。您可以使用codeigniter提供的功能。有两种功能可用于实现所需的结果。我更喜欢角色扮演 字符限制器 将字符串截断为指定的字符数。它保持了文字的完

我正在尝试实现各种文章的预览,预览应该是整篇文章的一小部分,以给读者和内容的想法

我目前的解决方案是将所有内容作为文本加载,并以最大宽度为300px的div显示,并隐藏溢出。虽然这确实有效,但似乎不是最好的解决方案

我认为使用mysql选择部分内容可能是一种选择。我应该如何获得预览,我应该只获得N个字符,还是MYSQL有更多针对这种行为的定制功能。

您可以使用codeigniter提供的功能。有两种功能可用于实现所需的结果。我更喜欢角色扮演

字符限制器 将字符串截断为指定的字符数。它保持了文字的完整性 字限制器 将字符串截断为指定的字数
$string = "Here is a nice text string consisting of eleven words.";
$string = character_limiter($string, 20);
// Returns:  Here is a nice text string
$string = "Here is a nice text string consisting of eleven words.";
$string = word_limiter($string, 4);
// Returns:  Here is a nice