note 45997 deleted from ref.simplexml by derick
| From: | derick@php.net | Date: | Thu, 13 Oct 2005 13:47:38 +0000 |
| Subject: | note 45997 deleted from ref.simplexml by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-96957@lists.php.net to get a copy of this message | ||
Note Submitter: farzan ath ifarzan dod com
----
You can access XML elements in a SimpleXML object using variables:
<?
$xml = simplexml_loaf_file(...);
print $xml->$element;
?>
or use functions:
<?
print $xml->{getLanguage()};
?>
Note: You Must use { and } or PHP would think you are calling a member function.
You can use members of other objects as well:
<?
print $xml->{$obj->var};
?>
As a real life example; I have used this statement in one of my projects:
<?
$x = $xrules->listing->fieldtitles->$lang->{$obj->name}->title;
?>
As you see, using varialbes and functions as element names are posible in SimpleXML; Thanks to
PHP5's object orientaion new features.