🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# PHP getNamespace() 函数 ## 定义和用法 getNamespace() 函数获取在 XML 文档中使用的命名空间。 如果成功,该函数返回命名空间(带有关联的 URL)的一个数组。如果失败,则返回 false。 ### 语法 ``` class SimpleXMLElement { string getNamespace(recursive) } ``` | 参数 | 描述 | | --- | --- | | recursive | 可选。规定是否返回父子节点中使用的所有命名空间。默认是 false。 | ## 例子 XML 文件: ``` <?xml version="1.0" encoding="ISO-8859-1"?> <note xmlns:b="http://www.w3school.com.cn/example/"> <to>George</to> <from>John</from> <heading>Reminder</heading> <b:body>Don't forget the meeting!</b:body> </note> ``` PHP 代码: ``` <?php if (file_exists('test.xml')) { $xml = simplexml_load_file('test.xml'); } print_r($xml->getNamespaces()); ?> ``` 输出类似: ``` Array ( [b] => http://www.w3school.com.cn/example/ ) ```