PHP attributes() फ़ंक्शन

परिभाषा और उपयोग

attributes() फ़ंक्शन SimpleXML एलीमेंट के गुण प्राप्त करता है。

यह फ़ंक्शन एक XML टैग में परिभाषित गुण और मूल्यों को प्रदान करता है。

व्याकरण

class SimpleXMLElement
{
string attributes(ns,is_prefix)
}
पारामीटर वर्णन
ns वैकल्पिक।जोखिम के लिए अनुसूचित गुण का नामस्पति
is_prefix वैकल्पिक।मूलभूत वाला false है।

उदाहरण

XML फ़ाइलः

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body type="small" important="low">Don't forget the meeting!</body>
</note>

PHP कोडः

<?php
$xml = simplexml_load_file("test.xml");
foreach($xml->body[0]->attributes() as $a => $b)
  {
  echo $a,'="',$b,'"';
  }
?>

आउटपुट:

type="small" important="low"