[英]PHP Get Array From URL
I'm trying to make a PHP array from a URL string. 我正在尝试从URL字符串制作一个PHP数组。
My code: 我的代码:
$files = urldecode($_POST['files']); // The String
error_log($files); // Output to see how it looks like
parse_str($files); // parse...
error_log($files[0]); // See the result
My Error_log after I run the script: 我运行脚本后的Error_log:
file[]=U07ttCL89
f
(If someone is wondering why I output with error_log
- it because I can't see the output) (如果有人想知道为什么我用
error_log
输出-这是因为我看不到输出)
Why is it returning f
after parsing? 为什么解析后返回
f
?
The $_POST['files']]
syntax is : $_POST['files']]
语法为:
file[]=XXXXXXXXX&file[]=YYYYYYYY&file[]=ZZZZZZZZZ
You have a typo. 你有错字 The new var is
file
not files
;) 新的var是
file
而不是files
;)
error_log($file[0]); // See the result
You can access a string like an array. 您可以访问类似数组的字符串。 If you use $files[0], you ouput the first char of the string, which is stored in $files.
如果使用$ files [0],则会输出字符串的第一个字符,该字符存储在$ files中。 In your case it is
file[]=XXXXXXXXX&file[]=YYYYYYYY&file[]=ZZZZZZZZZ
您的情况是
file[]=XXXXXXXXX&file[]=YYYYYYYY&file[]=ZZZZZZZZZ
Use this: 用这个:
$files = array();
$count = count($_POST['files']);
for($i=0;$i<$count;$i++){
$files[] = $_POST['files'][$i];
}
UPDATE: The answer is actually simpler 更新:答案实际上更简单
$files = $_POST['files'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.