0

I have a form with textarea (links one per line):

<textarea class="form-control" rows="10" name="links" id="links"></textarea>

and the php code:

function scrape($link) {
  $html = file_get_html("$link");
........
}

$links = $_POST["links"];
$lines = explode("\n", $links);

foreach($lines as $line){
  scrape($line);
}

Error: Warning: file_get_contents(site.com): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found

3
  • failed to open stream Commented Feb 9, 2015 at 21:41
  • I think that the problem is with quotes.All links work. Commented Feb 9, 2015 at 21:47
  • You've sure given us a bunch of information here Commented Feb 9, 2015 at 21:48

1 Answer 1

0

You can open a website via file_get_contents(); however, you need to provide the full URL to achieve that, e.g. : http://www.example.com. However, you may encouter problems with some pages, in which cases you could use CURL or StreamSockets to get (remote) websites.

Edit : Additionally, you should note that some OSes treat \r\n as what others "think" is a simple \n. You may try the script out with the former one; it proved to work on my Windows machine.

Sign up to request clarification or add additional context in comments.

2 Comments

I do not know what happens.When I put a single link in textarea,the script work well.When i put multiple links i got this error.The url is full(include http://)
Thanks.The problem is in explode: $lines = explode("\r\n", $links);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.