I will have a string like this:
Bob is a boy. Bob is 1000 years old! <b>Bob loves you!</b> Do you love bob?
I want to parse it into an array, using the following delimiters to identify each array element:
.
!
?
<b> and </b>
So I will have an array with the following structure:
[0]Bob is a boy.
[1]Bob is 1000 years old!
[2]Bob loves you!
[3]Do you love bob?
Any ideas?
As you can see, i’d like the text between <b> and </b> to be extracted, previously I’m using the following regexp to do it:
preg_match_all(":<b>(.*?)</b>:is", $text, $matches);
I think this should accomplish what you’re going for:
It yields:
The first line of the parser grabs each of the strings of text between the delimiters and their offsets in the string. The second line adds the punctuation marks from the original string to the end of each element.