我已经看到很多(在您将其标记为重复之前)如何执行此操作,但由于某种原因,我的输出无法正常工作:
// $delimiters wanted: ', ' | '; ' | ',' | ';' | ' , ' | ', and ' | ' and ' | ',and '
$str = 'Name 1, Name 2; Name 3;Name4 , Name 5,Name 6, and Name 7,and Name 8 and Name 9';
$delimiter = array(
', ',
'; ',
';',
',',
' , ',
', and ',
' and ',
',and '
);
$str_new = explode( $delimiter[0], str_replace($delimiter, $delimiter[0], $str) );
但是,当我输出数组时,我得到了这个:
<?php foreach($str_new as $new) { echo 'a' . $new; } ?>
Array (
[0] => Name 1
[1] => Name 2
[2] => Name 3
[3] => // WHY IS THIS EMPTY?
[4] => Name 4
...
)
那么有没有更好的方法来匹配我列出的分隔符?