在本地WAMP中获取原始输出相同的代码在Web服务器上工作正常 [英] getting raw output in local wamp same code working fine in webserver

查看:148
本文介绍了在本地WAMP中获取原始输出相同的代码在Web服务器上工作正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以在服务器上正常工作的脚本,但是在本地沼泽中却报错

i have this script which is workign just fine in server but in local wamp it is giving error

我打开了fopen

Warning: get_headers(): This function may only be used against URLs in C:\wamp\www\url\test5.php on line 8


<?php 
    $websitelink= 'http://www.brobible.com/girls/article/miley-cyrus-21st-birthday-party';
    $html = file_get_contents($websitelink); 
    $doc = new DOMDocument(); 
    @$doc->loadHTML($html); 
    $tags = $doc->getElementsByTagName('img'); 
    foreach ($tags as $tag) { 
        $data = get_headers($tag->getAttribute('src'),1); 
        $op7=''.$tag->getAttribute('src').'';
        echo $op7;
    }
?>

此代码仅能在服务器上正常运行,而不能在本地wamp服务器上运行

this code just works fine in server but not in local wamp server

推荐答案

根据您链接的屏幕截图,$op7的值为/files/img/nav/nav_02.png.那是一个相对于根的URL,get_headers()需要一个绝对URL(以'http://'开头).

The value of $op7 is /files/img/nav/nav_02.png according the the screenshot you linked. That is a root-relative URL, get_headers() requires an absolute URL (starting with 'http://').

您需要将要查询的域(http://www.brobible.com)粘贴到图像的根相对路径,以使其看起来像

You need to glue the domain you are querying (http://www.brobible.com) to the root-relative path of the image so that it looks like

get_headers('http://www.brobible.com'.$tag->getAttribute('src'),1)

请记住,这现在仅适用于相对于根的路径;您可能需要先检查绝对路径和相对路径,然后再假设它们需要以这种方式粘合域.

Keep in mind this will now only work with root-relative paths; you will probably want to check for absolute and relative paths before you assume they need the domain glued on this way.

这篇关于在本地WAMP中获取原始输出相同的代码在Web服务器上工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆