Suppose, I want to split a string based on delimiter. So I'd simple do a explode('. ', $myString)
. But, this strips out if there are any abbreviations present like U.K.
or U.S.
.
So, how could I use explode keeping all abbreviations intact.
Abbreviations will be of the form: X.Y.Z
While sentences would be separated by .
For example, The U.S. is a country. It's in N.America.
should result in:
[0] = The U.S. is a country.
[1] = It's in N.America.
Based on Split a text into sentences:
preg_split('/(?<=[.?!])\s+(?=[A-Z])/', "The U.S. is a country. It's in N.America.")
Output:
array(2) {
[0]=>
string(22) "The U.S. is a country."
[1]=>
string(18) "It's in N.America."
}