【问题标题】:Exploding an array in PHP with three delimiters [closed]使用三个分隔符在 PHP 中分解数组 [关闭]
【发布时间】:2014-07-12 18:07:21
【问题描述】:

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

这是数组:-

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);
                  }

我希望我能得到每个我可以使用的多维数组。

【问题讨论】:

  • 那么分隔符是什么?我可以看到|,我猜第二个是新行,那么第三个是什么?

标签: php arrays preg-replace explode


【解决方案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, '|');

【讨论】:

  • @Steve 是的,但没有你的例子,这个问题真的有点微不足道......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-10-25
  • 1970-01-01
  • 2017-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多