note 45997 added to ref.simplexml
| From: | farzanathifarzandodcom at osu1 dot php dot net | Date: | Sat, 25 Sep 2004 22:38:05 +0000 |
| Subject: | note 45997 added to ref.simplexml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-77324@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/ref.simplexml.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45997
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45997&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45997&report=yes
Search -- http://master.php.net/manage/user-notes.php