Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

new to php want a script to post data to a url and parse result (line microsoft.xmlhttp)

I'm new to php but learning fast.

I currently do the following sending 2 lots of strings to a external url that create metadata from the input, returning it as xml.

I want to do this within php (without any .JS) is this possible?

Points for full working code please.


existing code in javascript:

function fillMeta(title,content)
  var xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
  xmlHTTP.open("POST", "http://*********/categorise.pl?", false);
  xmlHTTP.send('XML_INPUT=<document><title>' + title + '</title><body>' + content + '</body></document>');
 var xmlDOM = new ActiveXObject("Microsoft.XMLDOM");

  s = xmlHTTP.ResponseText

  if (xmlDOM.parseError != 0)
   alert("Error occurred: " + xmlDOM.parseError.reason);
   return false;
  return s;
Neil Thompson
Neil Thompson
  • 2
1 Solution
you need to use fsockopen.
look at http://uk2.php.net/manual/en/function.fsockopen.php and you will find some example proposed by other users!
I would use curl-->http://us2.php.net/curl
Build your post string using the key=value&key2=value2 convention
curl_exec prints the output to the screen, so you need to use output buffereing as well.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
$postStr = 'xml_input='.urlencode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postStr);
curl_exec ($ch);
$response = ob_get_clean();
curl_close ($ch);

Neil ThompsonSenior Systems DeveloperAuthor Commented:
Cheers, Had a bit of a problem until I added libeay32.dll and ssleay32.dll to my Apache/bin directory and uncomment it in php.ini but now works fine.

Is curl the best thing to use to read the returned data and extract it.
If you're talking about parsing the xml data then no. If's it returning a valid xml document, I would recommend domxml if you're using php4 or either domxml or simplexml if your using php5

You would probably need to install domxml just like you did with curl. Instructions are on the page; very similar process.
If you're familiar with manipulating the DOM using javascript then this method is trivial to learn.
Although in php4, the domxml functions names are slightly different than the corresponding javascript functions; why this was done, I have no idea.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now