Hello,

I am getting response as xml from curl request. so i am sending these into an array. but after execution of code i am getting this warning
1)Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Start tag expected, '<' not found in C:\wamp\www\newlivebackup\admin\subscribers.php on line 65

2)Warning: simplexml_load_string() [function.simplexml-load-string]: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx in C:\wamp\www\newlivebackup\admin\subscribers.php on line 65

3)Warning: simplexml_load_string() [function.simplexml-load-string]: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx in C:\wamp\www\newlivebackup\admin\subscribers.php on line 65

Here is my code

$ch = curl_init();
  curl_setopt($ch, CURLOPT_URL,"http://url");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
  curl_setopt($ch, CURLOPT_HTTPHEADER,  array("Content-Type: application/x-www-form-urlencoded",  "Content-Length: " . strlen($req)));
  curl_setopt($ch, CURLOPT_HEADER , 0);  

  curl_setopt($ch, CURLOPT_VERBOSE, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  curl_setopt($ch, CURLOPT_TIMEOUT, 30);

  $curl_result = @curl_exec($ch);
  $curl_err = curl_error($ch);
  curl_close($ch);

//echo $curl_result;exit;
    // parse the data
    $curl_result = trim($curl_result);
$xml = (array) simplexml_load_string($curl_result);

Curl is not the problem. Apparently your called URL does not return valid XML. Check that one.

thanks for your reply.

i obsorb one thing in my code. the curl response

$curl_result = trim($curl_result);
$xml = (array) simplexml_load_string($curl_result);

instead of this i copied this response in a static file and then executed like below it is working fine.
$curl_xml=file_get_contents("file_path");
$xml = (array) simplexml_load_string($curl_xml);

so why it is not working

$curl_result = trim($curl_result);
$xml = (array) simplexml_load_string($curl_result);

Please tell me where the problem. actually the response is in valid xml format. is there any chance to save this response in one file. then i will execute. so how to save curl response in text file?

Don't know. Hard to guess without being able to try.

You can save the result with file_put_contents()

@Muralikalpana,

Just to clear some of my doubts, can you run this script on your wamp server

 <?php
 var_dump(curl_version());
 ?>

Did you see anything on the screen?

NO? Run

 <? phpinfo(); ?>

Look for your server loaded configuration file .. e.g. apache/bin/php.ini OR php/php.ini.. based on the loaded configuration file, find the php.ini file, load the php.ini file on your editor and then find

   ;extension=php_curl.dll

Change it to

   extension=php_curl.dll

Go to your wampp/php/ extension directory and double check if the php_curl.dll is present... if not, go and check the wampp website on how to enabled and add extension on their distros..

I am not sure if you can trim cURL output.. coming from the exec handler... I need to read about that..The output is already known by your server to be an array. So adding (array) might be an overkill..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.