-4

我在 html 中有一个表单,它将采用一个巨大的字符串,然后用空格、逗号和一个空格分隔,并且每个项目都用引号括起来,如下所示:

$s = '"info1" , "info2"'; //and so on

所以我的问题是如何创建一个新的数组变量并将字符串中的信息设置为数组中的信息?基本上是这样的:

$array_ex = array("info1", "info2"); //of course there is going to be
                                     //way more than 2 items

是否可以?

谢谢!

4

2 回答 2

3
$s = '"info1" , "info2"' //and so on

$array = explode(",",$s);


print_r($array)
于 2012-12-28T03:31:58.740 回答
0

explode 函数用于从具有特定分隔符的字符串生成数组。

作为上述问题的解决方案,您需要使用 explode 函数从用逗号分隔的字符串生成数组

例如

        $a=explode(",",$string);

有关爆炸功能的更多详细信息,请参阅以下网址中提到的文档

http://php.net/manual/en/function.explode.php

于 2012-12-28T06:12:15.780 回答