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

Posted on 2005-05-05
Last Modified: 2012-06-27
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");"POST", "http://*********/", 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;
Question by:NeilT
    LVL 16

    Expert Comment

    you need to use fsockopen.
    look at and you will find some example proposed by other users!
    LVL 11

    Accepted Solution

    I would use 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);

    LVL 3

    Author Comment

    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.
    LVL 11

    Expert Comment

    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

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now