Splitting a string on multiple separators in PHP

前端 未结 6 625
走了就别回头了
走了就别回头了 2021-01-25 03:50

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

6条回答
  •  日久生厌
    2021-01-25 04:57

    just add these chars to your expression

    $words = preg_split('/[;,. ]/', $string);
    

    EDIT: thanks to Igoris Azanovas, escaping dot in character class is not needed ;)

提交回复
热议问题