Content in xml parse script show as array instead html

58 Views Asked by At

When I parse xml one object is shown as array because it has

tags inside. How to use it as html content instead?

Here is xml data:

<product>
  <id>10001</id>
  <sku>SKU0001</sku>
  <name>Product name</name>
  <stock>SKU0001</stock>
  <description><p>Paragraph 1</p><p>Paragraph 2</p><p>Paragraph 3</p></description>
</product>

Here is part of my code:

$url = "https://url.com/products.xml";
$xml = simplexml_load_file($url) or die("feed not loading");
$sku = $xml->product->product_id;
$name = $xml->product->identifier;
$description = $xml->product->description;
$stock = $xml->product->stock;              
print_r($description);

print_r($description) returns me this:

SimpleXMLElement Object
(
    [p] => Array
        (
            [0] => Paragraph 1
            [1] => Paragraph 2
            [2] => Paragraph 3
        )

)

I would like to see $desription as html: <p>Paragraph 1</p><p>Paragraph 2</p><p>Paragraph 3</p>.

0

There are 0 best solutions below