Dear Friends
I have little problem, i have a variable whose name is $xml which carries all the xml data, now i want to make the array of that data, which parsing function can i use for this process which will directly parse my all data from that xml variable to array or give me any ideal suggestion for this process.
Thanks and Best Regards
xml variable to array
Moderator: General Moderators
Re: xml variable to array
You can use the simplexml_load_string() function:
It returns an object of class SimpleXMLElement with properties containing the data held within the xml document (within your $xml variable). You can find out more about this function here: PHP Manual simplexml_load_string
Code: Select all
$xml_obj = simplexml_load_string($xml);
var_dump($xml_obj);
Last edited by genconv on Fri Jul 10, 2009 7:23 am, edited 1 time in total.
Re: xml variable to array
You can also use the simplexml_load_file() function if you've got an XML file:
Code: Select all
if (file_exists('file.xml')) {
$xml = simplexml_load_file('file.xml');
var_dump($xml);
} else {
exit('Could not open file.xml.');
}
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: xml varialbe to array
There are several XML libraries.
http://us3.php.net/manual/en/refs.xml.php
Here is one:
http://us3.php.net/manual/en/function.s ... string.php
http://us3.php.net/manual/en/refs.xml.php
Here is one:
http://us3.php.net/manual/en/function.s ... string.php
(#10850)
-
habib009pk
- Forum Commoner
- Posts: 43
- Joined: Sun Jul 05, 2009 11:28 pm
Re: xml varialbe to array
Hi,
I am using your that code
$xml_obj = simplexml_load_string($xml);
var_dump($xml_obj);
but it always return bool(false);
I would like to ask that, can i include any file in my php page as i am working in dreamweaver.
Regards
I am using your that code
$xml_obj = simplexml_load_string($xml);
var_dump($xml_obj);
but it always return bool(false);
I would like to ask that, can i include any file in my php page as i am working in dreamweaver.
Regards