How to post XML using CURL?

Recently I was working in a hotel booking engine and found a couple of methods to post XML to server; I thought this might be good to share with my friends who want to post xml via HTTP POST method.

There are several ways to Send XML requests via HTTP POST.
I am going to show you two ways. Both are very simple and easy.

As first approach I have used a small xml file with CURL.


'.
    ''.
        '1234567890'.
        'lgsoftwares'.
        'mypassword'.
        'phpmind.com'.
    ''.
    ''.
        ''.
        ''.
    ''.
''.
'JHM'.
        'OGGSHE'.
        '101009'.
        '101509'.
        '1'.
  ''.  
  '';


$URL = "https://www.yourwebserver.com/path/";

			$ch = curl_init($URL);
			curl_setopt($ch, CURLOPT_MUTE, 1);
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
			curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$output = curl_exec($ch);
			curl_close($ch);

?>

Share

How to delete a folder with PHP?

To delete a file, or a folder and its contents i have compiled a recursive algorithm.
Hope this will be useful for all of you.

read()) {

      // Skip pointers

      if ($entry == '.' || $entry == '..') {

      continue;

      }
       
      // Recurse
      rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);

      }
       
      // Clean up
      $dir->close();

      return rmdir($dirname);

      }

?>
Share

How to display certain number of words from a record?

I got good php tutorial to display certain number of words from database; in place of Database record you can use any other regular string.

 300) {
$ext = "... read more";
} else {
$ext = "";
}
function elliStr($s,$n) {
for ( $x = 0; $x < strlen($s); $x++ ) {
$o = ($n+$x >= strlen($s)? $s : ($s{$n+$x} == " "?
substr($s,0,$n+$x) . "..." : ""));
if ( $o!= "" ) { return $o; }
}
}

echo (elliStr("$text", 300)) . $ext;
?>
Share

How to collect Checkbox Array values?

Beginner PHP Programmer always searches for easy way to collect Checkbox data from forms.
Here in this post I have used 3-4 lines of easy code to collect data from multi checkboxes. Instead of using several table-fields you can store your comma separated data in on field of the table. This is easy and handy.



 Om  Jyoti  Bruce
 Yaling  Angelica  Tara
Share