Search code examples
phpfile-get-contentsmaxlength

PHP - File Get Contents - Setting Maximum Length


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?


Solution

  • 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)