SimpleXMLElement->getNamespaces()
(PHP 5 >= 5.1.2)
SimpleXMLElement->getNamespaces() โ ใใญใฅใกใณใใงไฝฟ็จใใฆใใๅๅ็ฉบ้ใ่ฟใ
่ชฌๆ
SimpleXMLElement
array getNamespaces
([ bool $recursive
] )
ใใญใฅใกใณใใงไฝฟ็จใใฆใใๅๅ็ฉบ้ใ่ฟใใพใใ
ใใฉใกใผใฟ
- recursive
-
ๆๅฎใใใฆใใๅ ดๅใฏใ่ฆชใใผใใใใณๅญใใผใใงไฝฟ็จใใฆใใๅ จใฆใฎๅๅ็ฉบ้ใ่ฟใใพใใ ใใใฆใใชใๅ ดๅใฏใใซใผใใใผใใงไฝฟ็จใใฆใใๅๅ็ฉบ้ใฎใฟใ่ฟใใพใใ
่ฟใๅค
getNamespaces ใกใฝใใใฏใ ๅๅ็ฉบ้ๅใใใณ้ข้ฃไปใใใใ URI ใ้ ๅใง่ฟใใพใใ
ไพ
Example#1 ใใญใฅใกใณใใงไฝฟ็จใใฆใใๅๅ็ฉบ้ใฎๅๅพ
<?php
$xml = <<<XML
<?xml version="1.0" standalone="yes"?>
<people xmlns:p="https://example.org/ns" xmlns:t="https://example.org/test">
<p:person id="1">John Doe</p:person>
<p:person id="2">Susie Q. Public</p:person>
</people>
XML;
$sxe = new SimpleXMLElement($xml);
$namespaces = $sxe->getNamespaces(true);
var_dump($namespaces);
?>
ไธใฎไพใฎๅบๅใฏไปฅไธใจใชใใพใใ
array(1) { ["p"]=> string(21) "https://example.org/ns" }