having issue on curl_init

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Post Reply
User avatar
gether
New php-forum User
New php-forum User
Posts: 16
Joined: Tue Dec 25, 2012 7:38 pm

Re: having issue on curl_init

Post by gether » Mon Jan 28, 2013 3:16 am

i am noobie too ... looks complicated

us2rn4m2
New php-forum User
New php-forum User
Posts: 17
Joined: Thu Aug 09, 2012 1:28 pm

Re: having issue on curl_init

Post by us2rn4m2 » Mon Jan 28, 2013 6:21 am

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 
*/

User avatar
gether
New php-forum User
New php-forum User
Posts: 16
Joined: Tue Dec 25, 2012 7:38 pm

Re: having issue on curl_init

Post by gether » Mon Jan 28, 2013 10:03 am

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 ?

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest