I have seen many (before you go flagging this as a duplicate) on how to do this, but for some reason my output isn't working:
// $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) );
However, when I output the array, I get this:
<?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
...
)
So is there a better way to match the delimiters I have listed?