PHP children() Functie
Voorbeeld
Zoek de kinderen van het notitieknooppunt:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Do not forget me this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach ($xml->children() as $child)
{
echo "Child node: " . $child . "<br>";
}
?>
Definitie en gebruik
De functie children() vindt de kinderen van een opgegeven knooppunt.
Syntaxis
SimpleXMLElement::children(ns, prefix)
Parameterwaarden
Parameter | Description |
---|---|
ns | Optional. Specifies an XML namespace |
prefix | Optional. A Boolean value. If TRUE ns is regarded as a prefix. If FALSE ns is regarded as a namespace URL. Default is FALSE |
Technische details
Winstwaarde: | Retourneert een SimpleXMLElement-object |
---|---|
PHP-versie: | 5.0+ |
PHP-wijzigingslogboek: | PHP 5.2: de optionele prefix- parameter toegevoegd |
Meer voorbeelden
Voorbeeld
Zoek de kinderen van het lichaamsknooppunt:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body><span>Important!</span> Do
not forget me this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach ($xml->body[0]->children() as $child)
{
echo "Child node: " . $child . "<br>";
}
?>
❮ PHP SimpleXML-referentie