Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I receive an XML file through HTTP?

Status
Not open for further replies.

alohaaaron

Programmer
Mar 27, 2008
80
US
Hi, I have PHP 4.0 so don't have simple XML. I"m trying to use file_get_contents to read in the XML and then read the file till the end using fopen and other file commands. Is this correct or does a file actually exist? Thanks!

$xml = file_get_contents ('php://input') or die('file_get_contents (php://input)');

$fp = fopen($xml, 'r');

If I print the contents below using $HTTP_RAW_POST_DATA it displays the XML file that was posted

echo "<pre>";
print_r($HTTP_RAW_POST_DATA );
echo "</pre>";

 
you seem to assuming that the xml is available at the standard input. if you control the source of the xml or the receiving script, why not do the manipulations in that script rather than relying on sockets?
 
Thanks. The file xml file is sent by a 3rd party. Now I'm trying to put it into a database. I don't have access to simple xml or open xml. In the code below it prints out the xml file correctly. Here is the XML File.
$xml_data = "<?xml version=\"1.0\"?><member><Email>abc@home.com me</Email></member>";

How would I insert the email address into a database? Even though the email address abc@home.com is printed out correctly as Email: abc@home.com I don't see how to capture that variable and put it into a database? It's not $element_name since that's the field name.

//Function to use at the start of an element
function start($parser,$element_name,$element_attrs)
{
switch($element_name)
{
case "EMAIL":
echo "Email: "; break;
}
}
 
first of all migrate to php5. php4 has been end of lifed. people should not be writing new code for a platform that no longer has support.

if you do not have any modern parsing extensions, then consider xml_parse_into_struct.

insert the values into the database in the normal way.
 
Thanks. I have no control over what my vendor has installed on their platform. This includes no curl extension and no PHP 5.x

I'll check out the xml_parse_into_struct

 
of course you have control. just vote with your feet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top