phpstringexplodetext-segmentation

Explode a paragraph into sentences in PHP


I have been using

explode(".",$mystring)

to split a paragraph into sentences. However this doen't cover sentences that have been concluded with different punctuation such as ! ? : ;

Is there a way of using an array as a delimiter instead of a single character? Alternativly is there another neat way of splitting using various punctuation?

I tried

explode(("." || "?" || "!"),$mystring)

hopefully but it didn't work...


Solution

  • You can do:

    preg_split('/\.|\?|!/',$mystring);
    

    or (simpler):

    preg_split('/[.?!]/',$mystring);