我不认为有一个内置函数可以为你做这件事,但你可以做这样的事情:
键盘示例在这里
$string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque nec elit dui, nec fermentum velit. Nullam congue ipsum ac quam auctor nec massa nunc.";
$output = array();
while (strlen($string) > 50) {
$index = strpos($string, ' ', 50);
$output[] = trim(substr($string, 0, $index));
$string = substr($string, $index);
}
$output[] = trim($string);
var_dump($output);
// array(3) {
// [0]=>
// string(50) "Lorem ipsum dolor sit amet, consectetur adipiscing"
// [1]=>
// string(55) "elit. Quisque nec elit dui, nec fermentum velit. Nullam"
// [2]=>
// string(43) "congue ipsum ac quam auctor nec massa nunc."
// }