Php 一个字符串,其内容为数组到一个新数组
我有一个html格式的表单,它将采用一个巨大的字符串,后面用空格、逗号和空格分隔,每个项目都用引号括起来,如下所示:Php 一个字符串,其内容为数组到一个新数组,php,arrays,string,function,Php,Arrays,String,Function,我有一个html格式的表单,它将采用一个巨大的字符串,后面用空格、逗号和空格分隔,每个项目都用引号括起来,如下所示: $s = '"info1" , "info2"'; //and so on 所以我的问题是如何创建一个新的数组变量并将字符串中的信息设置为数组中的信息?基本上是这样做的: $array_ex = array("info1", "info2"); //of course there is going to be
$s = '"info1" , "info2"'; //and so on
所以我的问题是如何创建一个新的数组变量并将字符串中的信息设置为数组中的信息?基本上是这样做的:
$array_ex = array("info1", "info2"); //of course there is going to be
//way more than 2 items
可能吗
谢谢 explode函数用于从具有特定分隔字符的字符串生成数组
$s = '"info1" , "info2"' //and so on
$array = explode(",",$s);
print_r($array)
作为上述问题的解决方案,您需要使用explode函数从用逗号分隔的字符串生成数组
e、 g
$a=explode(",",$string);
有关explode函数的更多详细信息,请参阅以下url中提到的文档
关于堆栈溢出,每天至少有一个这样的问题。请参阅explode和其他许多问题。好的,我会的,很抱歉,我不知道要搜索什么。谢谢你可以看看这个: