<?php
$xml = <<<XML
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<Table Foo="Bar" ss:ExpandedColumnCount="7">
</Table>
</Workbook>
XML;
$sxml = new SimpleXMLElement($xml);
/**
* Access attribute of default namespace
*/
var_dump((string) $sxml->Table[0]['Foo']);
// outputs: 'Bar'
/**
* Access attribute of non-default namespace
*/
var_dump((int) $sxml->Table[0]['ExpandedColumnCount']);
// outputs: 0
var_dump((int) $sxml->Table[0]->attributes('ss', TRUE)->ExpandedColumnCount);
// outputs: '7'
?>
- Output for 7.3.16 - 7.3.33, 7.4.3 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- string(3) "Bar"
int(0)
int(7)
- Output for 5.4.0 - 5.4.17, 5.5.0, 7.2.29 - 7.2.33
- Parse error: syntax error, unexpected end of file in /in/deFEW on line 27
Process exited with code 255. - Output for 5.3.0 - 5.3.27
- Parse error: syntax error, unexpected $end in /in/deFEW on line 27
Process exited with code 255.
preferences:
161.04 ms | 401 KiB | 187 Q