Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

having issue on curl_init

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

having issue on curl_init

Postby santy143all » Mon Jan 28, 2013 3:05 am

Code: Select all
<?php
function build_query_string(array $params) {
$query_string = http_build_query($params);
return $query_string;
}
function curl_get($url) {
$client =curl_init($url);
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($client);
curl_close($client);
return $response;
}
?>


when i am calling this function it is showing unable tpo call any one please help me with same
waiting for response am newbie to the php. :help:
santy143all
New php-forum User
New php-forum User
 
Posts: 1
Joined: Mon Jan 28, 2013 3:00 am

Re: having issue on curl_init

Postby gether » Mon Jan 28, 2013 3:16 am

i am noobie too ... looks complicated
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

Postby 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
*/
us2rn4m2
New php-forum User
New php-forum User
 
Posts: 16
Joined: Thu Aug 09, 2012 1:28 pm

Re: having issue on curl_init

Postby 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 ?
User avatar
gether
New php-forum User
New php-forum User
 
Posts: 16
Joined: Tue Dec 25, 2012 7:38 pm


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron