Php 从SimpleXML对象提取属性

Php 从SimpleXML对象提取属性,php,simplexml,Php,Simplexml,如何从这个xml对象中提取属性 <designs> <tags> . . . </tags> <templates> <template id="photographysite" image="http://example.com/en/previews/photographysitePreview434x326.jpg" name="Shutter" thumb="http:/

如何从这个xml对象中提取属性

<designs>
    <tags>
    .
    .
    .
    </tags>
    <templates>
        <template id="photographysite" image="http://example.com/en/previews/photographysitePreview434x326.jpg" name="Shutter" thumb="http://example.com/en/previews/photographysitePreview182x137.jpg">
            <tag>all</tag>
            <tag>featured</tag>
            <tag>personal</tag>
            <tag>portfolio</tag>
            <tag>photography</tag>
            <tag>business</tag>
        </template>
    </templates>
</designs>


您可以使用数组表示法访问单个属性,例如

foreach ($xmldoc->templates->template as $template) {
    echo '<img src="', $template['thumb'], '"/>';
}
foreach($xmldoc->templates->template as$template){
回声';
}

请参见

您可以使用数组表示法访问单个属性,例如

foreach ($xmldoc->templates->template as $template) {
    echo '<img src="', $template['thumb'], '"/>';
}
foreach($xmldoc->templates->template as$template){
回声';
}

请参见

我只需要获取1个属性的值。那个么基本上是什么呢?我只需要得到1个属性的值。那基本上是什么呢?
foreach ($xmldoc->templates->template as $template) {
    echo '<img src="', $template['thumb'], '"/>';
}