使用三个分隔符在PHP中爆发数组

时间:2014-07-12 18:07:22

标签: php arrays preg-replace explode

我有一个我想要爆炸的阵列。该数组有三个分隔符,我想将它们放在三个不同的变量中。

这是数组: -

the_first|Little Detail|Some Large Details with a para of text
the_second|Little Detail|Some Large Details with a para of text
the_third|Little Detail|Some Large Details with a para of text

这是我做的: -

$extra_details =  "has the above array"


                  $array = array();
                  foreach ($extra_details as $r) {
                    $array[] = explode("|", $r);
                  }

我希望我可以使用多维数组获取每个数组,然后我可以使用它。

1 个答案:

答案 0 :(得分:1)

你在那里看起来像CSV,只是没有逗号分隔,但使用管道。 The function str_getcsv应该在这种情况下工作:

$inputString = <<<EOS
    the_first|Little Detail|Some Large Details with a para of text
    the_second|Little Detail|Some Large Details with a para of text
    the_third|Little Detail|Some Large Details with a para of text
EOS;

$outputArray = str_getcsv( $inputString, '|');
相关问题