我这里有一段代码描述了这个问题, 我需要在我的变量上运行file_get_html(), 有效参数必须为“http://google.com” 我的变量仅从域开始 - >添加http://和/,但是你可以看到它不起作用,它结束了:
Warning: file_get_contents('http://google.com/'): failed to open stream: Invalid argument ... simple_html_dom.php on line 75
这是代码
require_once('/simplehtmldom_1_5/simple_html_dom.php');
$a = 'google.com'; //from domain only: google.com
$b = "'http://" . $a . "/'"; //then, modify to have this form: http://google.com/
//$html = file_get_html($b); //this thing doesn't work
$html = file_get_html('http://google.com/'); // but this thing works
答案 0 :(得分:5)
在您的代码中,$b
的最终内容包含单引号,如果您正在处理变量,则不需要这些引号。
更改此行以删除单引号
$b = "'http://" . $a . "/'";
^ ^ Remove these.