Anna Wellington
Anna Wellington

Reputation: 323

Insert XML content to php

Can anyone please help me fetch an email address from an XML file & insert it to a php code? Please find the codes below.

XML CODE

<?xml version="1.0" encoding="UTF-8"?>
<document>
<data>
<emailaddress>[email protected]</emailaddress>
</data>
</document>

PHP CODE

if($_POST){
$to_email = "<?php $xml=simplexml_load_file("data.xml"); echo $xml->data->emailaddress;?>";
}

This php code does not pull the email address from the xml file. Can anyone suggest me a fix?

Thanks heaps in advance!

Cheers David

Upvotes: 0

Views: 97

Answers (1)

helpdoc
helpdoc

Reputation: 1990

Try this one (tested):

<?php
    if($_POST){ 
    $xml=simplexml_load_file("data.xml"); 

    echo $xml->data[0]->emailaddress;

    }

?>

Or Try like your code :

<?php
    if($_POST){
    $xml=simplexml_load_file("data.xml");
    $to_email =$xml->data[0]->emailaddress;
    echo $to_email;
    }
?>

Upvotes: 1

Related Questions