我可以打开一个HTTP地址与PHP不使用cURL或类似


Can I open an HTTP address with PHP without using cURL or similar?

PHP是否有任何本地工具来打开像http://example.com/a.rb?A=4这样的页面,然后将响应作为文本?

你可以使用file_get_contents(),但我认为curl是最好的方法。

这是一个很好的PHP类你必须知道http://simplehtmldom.sourceforge.net/

正如其他人提到的,您可以使用:

$var = file_get_contents("http://google.com");

或者你可以使用curl:

<?php
    // create curl resource
    $ch = curl_init();
    // set url
    curl_setopt($ch, CURLOPT_URL, "example.com");
    //return the transfer as a string
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // $output contains the output string
    $output = curl_exec($ch);
    // close curl resource to free up system resources
    curl_close($ch);     

?>

我复制了curl的例子:http://www.php.net/manual/en/curl.examples.php