我如何从PHP获取.jsp文件的输出?

I'm trying to do, for example, http://www.minecraft.net/haspaid.jsp?user=notch, which returns true. I want to basically make ?user=$somevariable from PHP and read whether the result returns true or false. Can anyone help?

$user="notch";
$result=file_get_contents("http://www.minecraft.net/haspaid.jsp?user=$notch"); 


if($result=="true")  
{
echo "Result is true";
}
else
{
echo "Result is false";

}

Note the double quotes around "true", since file_get_contents will return a string(on success) and not a Boolean value. You can cast it bool though if you want.

Try this:

$myVariable = "notch";
echo file_get_contents("http://www.minecraft.net/haspaid.jsp?user=$myVariable");

To what the others have said I recommend reading: http://php.net/manual/en/function.file-get-contents.php

You should urlencode() the variable containing the user-name before sending it in as well as using regex as to have some safety... I haven't tested the regex, but it should work. I also fixed the error in Hanky Panky:s suggested code, if you declare $user, you have to use that variable and not $notch in the URL.

$username = "notch";
$url = "http://www.minecraft.net/haspaid.jsp?user=". urlencode( preg_replace( "/[^\w ]/i" , "", $username ) );

$result = file_get_contents( $url );
$hasPaid = $result == "true";