I am trying to use file_get_contents() to get the html from a page.
the following works great: file_get_contents('http://www.mypage.com?Title=Title') but the following causes an error:
$Title = 'Title';
file_get_contents("http://www.mypage.com?Title=$Title")
The error is:
Bad Request
Your browser sent a request that this server could not understand.
The request line contained invalid characters following the protocol string.
Apache/1.3.41 Server at eiit.org Port 80
Does anyone know why?
You are using a string with single-quotes ; and there is no variable interpolation with single-quotes.
Which means the URL you’re trying to fetch is
http://www.mypage.com?Title=$Title, and nothttp://www.mypage.com?Title=Title.You should use a double-quoted string, to have variable interpolation :
If this still doesn’t work :
file_get_contents, store it in a variable, and echo it — just to be sure it’s right.www.mypage.comTitle=Titlehttp://www.mypage.com/index.php?Title=$Title? Or evenhttp://www.mypage.com/?Title=$Title?