php 警告:explode() 期望参数 2 是字符串,给定数组
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14114968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Warning: explode() expects parameter 2 to be string, array given
提问by user1938508
Im trying to use a script. And when I go to use it I get the following error:
我正在尝试使用脚本。当我去使用它时,我收到以下错误:
Warning: explode() expects parameter 2 to be string, array given in /myred/include/functions.php on line 16
Warning: in_array() expects parameter 2 to be array, null given in /myred/include/functions.php on line 17
警告:explode() 期望参数 2 是字符串,数组在第 16 行的 /myred/include/functions.php 中给出
警告:in_array() 期望参数 2 是数组,在第 17 行的 /myred/include/functions.php 中给出空值
Now, Below is line 16 and 17 of the functions.php. Anyone have any idea what is wrong with it?
现在,下面是functions.php 的第16 和17 行。任何人都知道它有什么问题吗?
$reserved = explode("--",$reserved);
if (in_array("$dname", $reserved)) {
$errormsg .= "$text_17<br>";
}
return $errormsg;
For reference, this is the script I am using: http://www.milliscripts.at/downloads/myred_14_mysql_5.zip
作为参考,这是我使用的脚本:http: //www.milliscripts.at/downloads/myred_14_mysql_5.zip
THANKS!
谢谢!
回答by rcorrie
It's simple, on line 16, your trying to explode an array, look at the php manual for explode, it splits a string by any delimiter you specify.
很简单,在第 16 行,您尝试explode分解一个数组,查看 php 手册 for ,它会按您指定的任何分隔符拆分字符串。
Since $reservedon line 16 is failing, line 17 fails too because $reservedis not being set properly.
由于$reserved第 16 行失败,第 17 行也失败,因为$reserved没有正确设置。
Post more code, we need to see where $reservedis first being declared.
发布更多代码,我们需要查看$reserved首先声明的位置。
回答by leepowers
This line is the cause of your woes:
这条线是你的困境的原因:
$reserved = explode("--",$reserved);
From the error message it appears the $reservedis already an array. I'm going to guess at it and say that each element of the initial $reservedarray are strings that contain "--"that you want to split on.
从错误消息看来,$reserved它已经是一个数组。我将猜测它并说初始$reserved数组的每个元素都是包含"--"要拆分的字符串。
If this assumption is right you'll need to convert $reservedto a string using implode():
如果这个假设是正确的,你需要$reserved使用implode()以下方法转换为字符串:
$reserved = explode("--", implode($reserved));
Which will solve the error and potentially give you the results you're looking for.
这将解决错误并可能为您提供您正在寻找的结果。

