Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
(PHP)文件\u获取\u内容-问号后的内容url?_Php_Curl - Fatal编程技术网

(PHP)文件\u获取\u内容-问号后的内容url?

(PHP)文件\u获取\u内容-问号后的内容url?,php,curl,Php,Curl,首先,我是PHP新手。我有下面的代码片段,它工作得很好 <?php $html = file_get_contents('http://www.example.com/'); preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i',$html, $matches ); foreach ($matches[1] as $match) { echo '<img src="' . $match . '" />

首先,我是PHP新手。我有下面的代码片段,它工作得很好

<?php

$html = file_get_contents('http://www.example.com/');
preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i',$html, $matches ); 


foreach ($matches[1] as $match) { 
    echo '<img src="' . $match . '" />';
}
?>
如何做到这一点?这是卷发吗

解决方案:

更改:

$html = file_get_contents('http://www.example.com/');


工作!:

您能否共享应用preg_match_all的内容?否-您应该将url参数添加为?url=。然后你可以使用$\u GET['url']访问cURL和file\u GET\u content。我不知道你在想什么。是http://www.example.com/getfile.php?http://www.url.com/images/ 一个真实的地点?你能在你的网络浏览器中打开它吗?@这家伙有两个拇指,非常感谢!有关解决方案,请参阅我的编辑:请注意,您面临XSS的严重风险。恶意用户可能会创建一个链接,例如http://example.com/getfile.php?url=http://evilsite.com/hax,它将包含精心编制的代码,可以将任何他们想要的东西注入到您的页面中。@阿尔瓦罗冈萨雷斯也许不是最好的解决方案,是吗;我仍然不能完全确定问题出在哪里。你想写一个在线服务从任意网站上抓取图片吗?@lvaroGonzález是的:仅供个人使用。你添加了一个功能,这样你的本地文件系统也可以被抓取
$html = file_get_contents('http://www.example.com/');
$html = file_get_contents($_GET["url"]);