在php中获取2个字符串之间的字符串

I am developing a website in php. I want to get a sub string in between two strings My main string is "ABCDEF ABCDEFGH ABCDEFGHIJ ABCDEFGHIJKLM ". I need to get the sub string in between last 2 s.(ABCDEFGHIJKLM)... Can you please help me for this issue.

Thanks Sateesh

$words = 'ABCDEF
ABCDEFGH
ABCDEFGHIJ
ABCDEFGHIJKLM
';   
$words = explode('
', $words);
$word = $words[count($words) - 2];

demo

You can use the Split() function to tokenise the string. You can then locate the relevant part of the string....

http://php.net/manual/en/function.split.php

NOTE As advised below the use of this function is no longer recomended as it has been Deprecated from the PHP spec from 5.3 onwards. The correct answer would be to use the Explode() function - as shown in the other answers above.

If the number of is unknown, you can use:

$string = "ABCDEF
ABCDEFGH
ABCDEFGHIJ
ABCDEFGHIJKLM
";

$words = explode("
", trim($string));
$last = array_pop($words);

echo $last;

Question: Do you want a newline (" ") or literally ' ' (backslash n)?

$lines = explode("
", trim($string));
$lastLine = $lines[count($lines) - 1];

http://ideone.com/Qo8UY

or just (because when we trim the whitespaces away, we are looking for the last element)

$lastLine = end($lines);

http://ideone.com/DzvK6