jclarke
09-01-2006, 07:26 PM
I have a string from an xml file that looks something like this:
<product>
<brand>Jonsered</brand>
<name>CS 2121 EL</name>
<type>Chainsaw</type>
<colour>Red</colour>
<ID>1</ID>
<price>---</price>
<description>
While versatile electric CS2121EL is perfect for pruning around the garder and precision cutting.[br]
</description>
</product>
I want to be able to seperate each product's attributes into a multi-dimensional array.
so far I can do this:
$productsFile_text = file_get_contents("xml/products.xml");
$products_array = explode("</product>",$productsFile_text);
$products_array = implode("",$products_array);
$products_array = explode("<product>",$products_array);
so that split's up all the products (there is more than 1 of them) into and array with the tags "brand" and "price" etc. in each part of the array.
But when it comes to the loop that will create a new array with all the data it eg.
$new_products_array = array();
for($i = 0; $i < count($products_array); $i++) {
//do summat like
$new_products_array[] = ("brand" => $daBrand,"name" => $daName etc.);
}
I just don't know how to get the content in between the tags "<brand>content</brand>". In javascript i know i could do something like:
curBrand = prods[i].getElementByTagNames("brand")[0].innerHTML;
But is there any way to do that or similar in php?
I know this is a long post, but any help would be muchly appreciated! :)
[/code]
<product>
<brand>Jonsered</brand>
<name>CS 2121 EL</name>
<type>Chainsaw</type>
<colour>Red</colour>
<ID>1</ID>
<price>---</price>
<description>
While versatile electric CS2121EL is perfect for pruning around the garder and precision cutting.[br]
</description>
</product>
I want to be able to seperate each product's attributes into a multi-dimensional array.
so far I can do this:
$productsFile_text = file_get_contents("xml/products.xml");
$products_array = explode("</product>",$productsFile_text);
$products_array = implode("",$products_array);
$products_array = explode("<product>",$products_array);
so that split's up all the products (there is more than 1 of them) into and array with the tags "brand" and "price" etc. in each part of the array.
But when it comes to the loop that will create a new array with all the data it eg.
$new_products_array = array();
for($i = 0; $i < count($products_array); $i++) {
//do summat like
$new_products_array[] = ("brand" => $daBrand,"name" => $daName etc.);
}
I just don't know how to get the content in between the tags "<brand>content</brand>". In javascript i know i could do something like:
curBrand = prods[i].getElementByTagNames("brand")[0].innerHTML;
But is there any way to do that or similar in php?
I know this is a long post, but any help would be muchly appreciated! :)
[/code]