0

我对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);       

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

4

1 回答 1

1

file_get_contents像 unix 一样工作wget,所以你可以简单地尝试:

echo file_get_contents('http://www.hookah-shisha.com/c-4-hookah-coals-hookah-charcoal.html');
于 2013-07-12T12:50:23.033 回答