开发者

Warning: file_get_contents(http://www.domain.com/emails.html ) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404

开发者 https://www.devze.com 2023-03-26 04:14 出处:网络
What I\'m attempting to do is post multiple url\'s which are exploded by a line break, get and then concatenate the contents of all files.

What I'm attempting to do is post multiple url's which are exploded by a line break, get and then concatenate the contents of all files.

The problem is, it returns;

Warning: file_get_contents(http://www.domain.com/emails.html ) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /nfs/c09/h02/mre/137842/domains/domain.com/html/index.php on line 6

For all but the last url.

Things that I've noted;

  • I've tried using urlencode() but that completely destroys the HTTP request.
  • There seems to be a space between the last character of the URL and the closing bracket, when I attempt to enter the url with a space into the browser it works fine (but this could be the browser rewriting an invalid URL?)

Here's my code for good measure;

$urls = explode("\n", $_POST['urls']);
$allTexts = '';
foreach($urls as $url)
{
    $text = file_get_contents($url);
    if (false === $text)
        continue;

    // proceed with your text, e.g. concatinating it:
    $allTexts .= $text;
}

Any advice or comments would be greatl开发者_运维技巧y appreciated (although I'd rather not use cURL if I don't need to :))!

0

精彩评论

暂无评论...
验证码 换一张
取 消