ฟังก์ชัน getNamespace() ของ PHP

การกำหนดและการใช้งาน

ฟังก์ชัน getNamespace() ของ PHP ใช้กับชื่อสาขาที่ใช้ในเอกสาร XML

ถ้าประสบความสำเร็จ ฟังก์ชันนี้จะกลับค่าแบบ array ของชื่อสาขา (พร้อมด้วย URL ที่เกี่ยวข้อง) ถ้าล้มเหลว ก็จะกลับค่า false

รูปแบบ

class SimpleXMLElement
{
string getNamespace();recursive)
}
ตัวแปร รายละเอียด
recursive ทางเลือกต่าง ๆ กำหนดว่าจะกลับค่าหรือไม่ของทุกชื่อสาขาที่ใช้ในต้นโค้ดเดียวกัน โดยมาตรฐานค่าเริ่มต้นคือ false

ตัวอย่าง

ไฟล์ XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<note xmlns:b="http://www.codew3c.com/example/"></note>
<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.codew3c.com/example/
)