如何从服务器到android获取变量php

Consider we have the following code in a php file:

$error = 'error';
echo "$error";

I search in internet and I find the example about this only and only using JSON. I want know how can I create a function to get the $error variable that has been sent from php. Please do not give me links and I want know How can I get the $error, I think the something like the following But really I do not know what should I do.

public void getVariable (String error)
{
How can I get the variable from php file?
}

in short: I want to have the contents of the $error variable in a java variable.

You can use HttpUrlConnection to connect to the php script and BufferedInputStream to get the data

URL url= new URL("http://...yourfile.php");
HttpUrlConnection con= (HttpURLConnection) url.openConnection();
con.setDoInput(true);

InputStream inputStream = new BufferedInputStream(con.getInputStream());
String result = readStream(inputStream); // s now contains the value you need