0

I have a piece of XML that looks like this:

<root>
<element>Normal,<b>Bold</b></element>
</root>

How can I use PHP to echo everything within <element>, so that the output is "Normal,<b>Bold</b>"?

EDIT: Here is my code:

<?php
$xml = simplexml_load_file('xml_file.xml');
$element = $xml->element;
echo $element[1];
?>

I just get "Normal".

jhunter_d
  • 65
  • 8

1 Answers1

0
$xml = '<root>
<element>Normal,<b>Bold</b></element>
</root>';

$sxe = new SimpleXMLElement($xml);
echo strip_tags($sxe->element->asXML());

You must strip tags when you match your element.

Piotr Olaszewski
  • 6,017
  • 5
  • 38
  • 65
  • 1
    This will strip the ``-tags too. Also creating the XMLElement is too much effort. A simple `echo strip_tags($xml);` outputs the very same result. – insertusernamehere Feb 18 '13 at 16:01