having issue on curl_init
Moderators: egami, macek, gesf
Ok, I am sending you an example that I wrote when I started to learn PHP:
Code: Select all
$url = 'http://www.webservicex.net/length.asmx/ChangeLengthUnit?';
$params = array(
'LengthValue' => '100',
'fromLengthUnit' => 'Kilometers',
'toLengthUnit' => 'Miles');
$request = $url . http_build_query($params);
function curl_get($request) {
$curl_init = curl_init() or die(curl_error());
curl_setopt($curl_init, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl_init, CURLOPT_URL, $request);
$response = curl_exec($curl_init);
curl_close($curl_init);
return $response;
}
$response = curl_get($request);
echo '<pre>';
echo htmlspecialchars($response);
echo '</pre>';
echo '<br />';
echo '100 Kilometers = ' . $response . ' Miles';
/* Result:
<?xml version="1.0" encoding="utf-8"?>
<double xmlns="http://www.webserviceX.NET/">62.137119223733393</double>
100 Kilometers = 62.137119223733393 Miles
*/
why do you have to put a $sign every where?
url = 'http://www.webservicex.net/length.asmx/ChangeLengthUnit?';
params = array(
'LengthValue' => '100',
'fromLengthUnit' => 'Kilometers',
'toLengthUnit' => 'Miles');
request = url . http_build_query(params);
why not like this ?
url = 'http://www.webservicex.net/length.asmx/ChangeLengthUnit?';
params = array(
'LengthValue' => '100',
'fromLengthUnit' => 'Kilometers',
'toLengthUnit' => 'Miles');
request = url . http_build_query(params);
why not like this ?