0

I am trying to get the contents of a web page up to the 100th character. However, for some reason the code isn't getting the web page at ALL.

Here's my code:

$link = "http://www.roblox.com/User.aspx?ID=1";
echo file_get_contents($link, NULL, NULL, -1, 100);

The reason I am wanting to do this is to get the title of that web page. I cannot figure out why it won't display. Probably the 3rd argument, which I've tried making an alternative for:

$opts = array('http'=>array('method'=>"GET",'header'=>"Accept-language: en\r\n" ."Cookie: foo=bar\r\n");

Even with the above variable set for the 3rd argument it doesn't work. Any suggestions?

3
  • look at the source code.. it's getting the doctype part of your target.
    – tradyblix
    Commented Oct 10, 2012 at 9:14
  • Yeah I noticed, however it won't even give me the doctype element. It's giving me null.
    – Anonymous
    Commented Oct 10, 2012 at 9:15
  • if I assign the file_get_contents part to a variable and var_dump it it's displaying the doctype string. def not null.
    – tradyblix
    Commented Oct 10, 2012 at 9:18

2 Answers 2

1

You can try

$link = "http://www.roblox.com/User.aspx?ID=1";
var_dump(file_get_contents($link, NULL, NULL, 0, 100));

Output

string '



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/' (length=100)
1

use this

echo substr(file_get_contents($link),0,100);
2
  • That's the thing. I am using this function a lot and trying to reduce bandwidth so it doesn't do me any good. I think I know what's wrong, however.
    – Anonymous
    Commented Oct 10, 2012 at 9:18
  • thanks though... it'd work if I wasn't wanting to use it for bandwidth. +1
    – Anonymous
    Commented Oct 10, 2012 at 9:23

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.