PHP file_get_contents为同一个域的不同行为

时间:2013-07-12 11:45:59

标签: php

关于 file_get_contents ,我可能有一个非常愚蠢的问题,我想检索一个网站上的内容,当我提供以下代码时,这可以正常运行:

$file = file_get_contents( $dataSourceURL, false, $context );

$ dataSourceURL ='http://somedomain.com',但是当我提供此网站的特定网页时,例如$ dataSourceURL ='http://somedomain.com/c-4-hookah-coals-hookah-charcoal.html',则不会返回任何内容。

有人对这个问题有所了解吗?

更新

我知道我们可以使用以下代码传递GET参数:

            $getdata = http_build_query(
                array(
                    'var1' => 'some content',
                    'var2' => 'doh'
                )
            );

            $opts = array('http' =>
                array(
                    'method'  => 'GET',
                    'header'  => 'Content-type: application/x-www-form-urlencoded',
                    'content' => $getdata
                )
            );

            $context  = stream_context_create($opts);       

但是...是否有一种简单的方法来解决这种网址查询'c-4-hookah-coals-hookah-charcoal.html'?

1 个答案:

答案 0 :(得分:1)

file_get_contents的作用类似于unix wget,因此您可以尝试简单:

echo file_get_contents('http://www.hookah-shisha.com/c-4-hookah-coals-hookah-charcoal.html');