我能告诉我的php函数直到;文件“获取内容”;是否已在php代码中使用javascript加载页面?
这是我的php函数:我能告诉我的php函数直到;文件“获取内容”;是否已在php代码中使用javascript加载页面?,javascript,php,return,delay,file-get-contents,Javascript,Php,Return,Delay,File Get Contents,这是我的php函数: $result = file_get_contents('https://www.example.com/index.php'); $regex = '/<img class="pic" src="(.*?)">/'; preg_match($regex, $result, $matches); return($matches[1]); $result=file\u get\u contents('https://www.example.com/in
$result = file_get_contents('https://www.example.com/index.php');
$regex = '/<img class="pic" src="(.*?)">/';
preg_match($regex, $result, $matches);
return($matches[1]);
$result=file\u get\u contents('https://www.example.com/index.php');
$regex='/';
预匹配($regex,$result,$matches);
返回($matches[1]);
这是一个从该链接获取图片的函数,有时返回图片,有时不返回,因为站点中的图像有时需要二次加载,有时不加载。
我想防止这种情况发生在我的函数中,我想延迟返回直到加载图像,我知道这在php中是不可能的,sleep()没有帮助,所以我知道我必须用javascript来完成,但我不知道如何完成,请帮助我 如果您希望异步加载某些内容,我想最简单的解决方案是从客户端启动另一个请求,例如:
fetchimage.php
内容类型标题。样品。因此,您的代码需要修改,请参见下文
src=“/fetch image.php”
属性替换为获取脚本的路径$result=file\u get\u contents('https://www.example.com/index.php');
$regex='/';
预匹配($regex,$result,$matches);
回显文件获取内容($matches[1]);
希望对您有所帮助。如果您使用file_get_contents()获取页面,您将只获得HTML文档。它不会加载外部资源(如图像、css、js)或在页面上执行任何javascript。好的,还有其他命令吗?谢谢帮助,这有点难,但我会试试