note 81217 modified in ref.simplexml by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 May 2009 01:14:52 +0000 |
| Subject: | note 81217 modified in ref.simplexml by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155502@lists.php.net to get a copy of this message | ||
Be careful using nested SimpleXML objects in double quoted strings.
<?php
$xmlstring =
'<root><node>123</node><foo><bar>456</bar></foo></root>';
$root = simplexml_load_string($xmlstring);
echo "Node is: $root->node"; // Works: Node is 123
echo "Bar is: $root->foo->bar"; // Doesn't work, outputs: Bar is: ->bar
// use curly brackets to fix
echo "Bar is: {$root->foo->bar}"; // Works: Bar is 456
?>
--was--
Be careful using nested SimpleXML objects in double quoted strings.
<?php
$xmlstring =
'<root><node>123</node><foo><bar>456</bar></foo></root>';
$root = simplexml_load_string($xmlstring);
echo "Node is: $root->node"; // Works: Node is 123
echo "Bar is: $root->foo->bar"; // Doesn't work, outputs: Bar is: ->bar
// use curly brackets to fix
echo "Bar is: {$root->foo->bar}"; // Works: Bar is 456
?>
http://php.net/manual/en/ref.simplexml.php