Skip to content
Thomas Weinert edited this page Jul 12, 2018 · 2 revisions

FluentDOM\Query::attr()

FluentDOM\Query attr(string|array $attribute [, string|callable $value = NULL ]);

Access a property on the first matched element or set the attribute(s) of all matched elements.

Usage - reading XHTML with namespace

$xml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<html:html xmlns:html='http://www.w3.org/1999/xhtml'>
 <html:head>
  <html:title>Examples: FluentDOM\Query::attr()</html:title>
 </html:head>
 <html:body>
  <html:p>
   Always nice to visit
   <html:a href='http://fluentdom.org'>here.</html:a>
  </html:p>
 </html:body>
</html:html>
XML;

$fdQuery = FluentDOM($xml);
$fdQuery->registerNamespace('h', 'http://www.w3.org/1999/xhtml');
echo $fdQuery
  ->find('//h:a')
  ->attr('href');

Output

http://fluentdom.org
Clone this wiki locally