I can split a string with a comma using preg_split, like
$words = preg_split('/[,]/', $string);
How can I use a dot, a space and a semicolon to split string with any of these?
PS. I couldn’t find any relevant example on the PHP preg_split page, that’s why I am asking.
Try this:
The Pattern explained
[]is a character class, a character class consists of multiple characters and matches to one of the characters which are inside the class.matches the.Character, this does not need to be escaped inside character classes. Though this needs to be escaped when not in a character class, because.means “match any character”.\smatches whitespace;to split on the semicolon, this needs not to be escaped, because it has not special meaning.The
+at the end ensures that spaces after the split characters do not show up as matches