这应该适合你:
<?php
$string = 'PHP Coding.
Hello World!
Merry Christmas!
Happy New Year!
Merry Super Early Next Christmas?
I want Pizza, and Cake
Hehehe
Hohohoho';
list($sentence[], $sentence[], $sentence[]) = array_slice(explode(PHP_EOL, $string), -3, 3);
print_r($sentence);
?>
输出:
Array ( [2] => Hohohoho [1] => Hehehe [0] => I want Pizza, and Cake )
编辑 :
在这里你可以从后面定义你想要多少个句子:
<?php
$string = 'PHP Coding.
Hello World!
Merry Christmas!
Happy New Year!
Merry Super Early Next Christmas?
I want Pizza, and Cake
Hehehe
Hohohoho';
$n = 3;
$sentence = array_slice(explode(PHP_EOL, $string), -($n), $n);
$sentence = array_slice(explode(PHP_EOL, nl2br($string)), -($n), $n); // Use this for echoing out in HTML
print_r($sentence);
?>
输出:
Array ( [0] => I want Pizza, and Cake [1] => Hehehe [2] => Hohohoho )