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
.and...? or if there is direct speech - does it work correctly? or initials, for exampleМ. Ю. Лермонтов?- Alexey Shimanskypreg_split('/[^a-zа-яё]+/ui', $input), not? - Dmitriy Simushev