Php 注意:{Error}中的数组到字符串转换
我必须建立一个目录并保存文件,但有一个错误写在标题中。帮我解决这个错误。我的代码如下Php 注意:{Error}中的数组到字符串转换,php,Php,我必须建立一个目录并保存文件,但有一个错误写在标题中。帮我解决这个错误。我的代码如下 function main() { $scrapper = new Cloaked_Scraper(); // Prefix of URL's $url_prefix = "link"; // URL $urls = array("www.something.com?"); // Get ID from every URL and wi
function main() {
$scrapper = new Cloaked_Scraper();
// Prefix of URL's
$url_prefix = "link";
// URL
$urls = array("www.something.com?");
// Get ID from every URL and will save on index one of $url array
$urls[1] = ((explode("www.something.com?id=com.", $urls[0])));
$urls[0] = $url_prefix;
$urls[0];
$urls[1];
//mkdir("../temp/", 0777 /* The mode is 0777 by default, which means the widest possible access */);
// Destination folder where this file will save, and file name.
$output_dir[0] = "../temp/".$urls[0].$urls[1].".html";
$results = $scrapper->fetch($urls, $output_dir);
var_dump($results);
}
main();
将字符串分解为字符串数组,详细说明,$url[1]
包含:数组(“”,'id=com')代码>
现在尝试将此数组作为此行插入:
$output_dir[0] = "../temp/".$urls[0].$urls[1].".html";
只需为字符串使用正确的索引:
$output_dir[0] = "../temp/".$urls[0].$urls[1][0].".html";
我不知道什么是隐藏的
,但它的获取
方法似乎只接受字符串作为第一个或第二个参数。将一个数组传递给它们两个
我认为$output\u dir
需要是一个普通的字符串,但是通过将$output\u dir[0]
赋值给它,就可以隐式地将它变成一个数组
将该行更改为此,然后查看发生了什么:
$output_dir = "../temp/".$urls[0].$urls[1].".html";
但总的来说,我认为您的代码非常混乱。看起来您是在循环使用$url
数组的项,而实际上应该使用单独的变量 请提供完整的错误消息(带行号)
$output_dir = "../temp/".$urls[0].$urls[1].".html";