How to maximally functionally split a sentence divided by N-spaces and punctuation marks into an array of words?

$array = explode(" ", preg_replace('|\s+|', ' ', str_replace(array(".", "?", "!", "...", ";", ",", "-"), "", $string))); 

This option is just tin, but it works. First I get the original sentence without punctuation, then I replace all spaces with one space. And then I get an array of words, through explode with a space separator. How can you make it more beautiful? = 3

  • that is, you want to say that in this version there is no confusion between . and ... ? or if there is direct speech - does it work correctly? or initials, for example М. Ю. Лермонтов? - Alexey Shimansky
  • how then to get around this? - Kryshtop
  • one
    @Kryshtop, do you not read the answers to your other questions ? preg_split('/[^a-zа-яё]+/ui', $input) , not? - Dmitriy Simushev

0