Hi i have an xml data like this
<Product>
<ProductID>13078</ProductID>
<image1>
image_url
</image1>
<image2>
image_url
</image2>
<image3>
image_url
</image3>
</Product>
i want to access images please help!!!
Hi i have an xml data like this
<Product>
<ProductID>13078</ProductID>
<image1>
image_url
</image1>
<image2>
image_url
</image2>
<image3>
image_url
</image3>
</Product>
i want to access images please help!!!
You can do it using SimpleXMLElement
$xml = simplexml_load_string($xmlString, "SimpleXMLElement");
$json = json_encode($xml);
$array = json_decode($json,TRUE);
unset($array['ProductID']); // You don't want 'ProductID' then You can remove it using unset().
$i=1;
foreach($array as $key=>$val){
echo $array['image'.$i]; // Here you can get all images in one echo
$i++;
}
if (file_exists('test.xml')) {
$xml = simplexml_load_file('test.xml');
print_r($xml);
}
you will get a result array
or else if you have XML string use this function
$xml = simplexml_load_string($string);
print_r($xml);
hope this will help you
Your Solution:
$string = '<Product>
<ProductID>13078</ProductID>
<image1>
image_url
</image1>
<image2>
image_url
</image2>
<image3>
image_url
</image3>
</Product>';
$xml = simplexml_load_string($string);
echo $xml->image1;