Link to home
Start Free TrialLog in
Avatar of intazaar
intazaar

asked on

PHP and XML

hi,
how do i use PHP to get information out of XML files, i want to take each section and put it into a php variable for example

$to = "james";
$from = "glen";
$heading = "reminder";
$body = "hello";

the information is taken from:

<email>
<to>james</to>
<from>glen</from>
<heading>Reminder</heading>
<body>hello</body>
</email>

thanks
Avatar of HuyBD
HuyBD
Flag of Viet Nam image

try use DOMDocument

$document = new DOMDocument();
$document->load('./yourfile.xml');
$el=$document->getElementsByTagName("email");


$to =$el->item(0)->getElementsByTagName("to")->item(0)->nodeValue;
$from =$el->item(0)->getElementsByTagName("from")->item(0)->nodeValue;
$heading = $el->item(0)->getElementsByTagName("heading")->item(0)->nodeValue;
$body = $el->item(0)->getElementsByTagName("body")->item(0)->nodeValue;

look at this: http://www.php.net/dom
Avatar of intazaar
intazaar

ASKER

will it work for php 4?
but then what would the code be?
ASKER CERTIFIED SOLUTION
Avatar of HuyBD
HuyBD
Flag of Viet Nam image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial