Home  >  Article  >  Backend Development  >  How to use php attributes function

How to use php attributes function

藏色散人
藏色散人Original
2019-05-27 11:08:372331browse

php attributes function is used to return the attributes and values ​​of XML tags. Its syntax is attributes(ns,is_prefix). The parameter ns is optional and specifies the namespace of the retrieved attributes; is_prefix is ​​optional and specifies a Boolean value.

How to use php attributes function

#How to use the php attributes function?

Definition and Usage

The attributes() function returns the attributes and values ​​of the XML tag.

Syntax

attributes(ns,is_prefix);

Parameters

ns Optional. Specifies the namespace of the properties to be retrieved.

is_prefix Optional. Specifies a boolean value. TRUE if ns is a prefix, FALSE if ns is a URI. Default is FALSE.

Return value: If successful, a SimpleXMLElement object is returned.

PHP Version: 5.0.1

Example

Return the attributes and values ​​of the XML body element:

<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body date="2013-01-01" type="private">Don&#39;t forget me this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach($xml->body[0]->attributes() as $a => $b)
{
echo $a,&#39;="&#39;,$b,""<br>";
}
?>

The above is the detailed content of How to use php attributes function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn