douchu5131
2013-12-06 08:35
浏览 187

如何从XML文件中获取参数?

I want to get an href from my XML parameters file; this is my code:

$linkx = $params->get('linkx'); 
echo '<a href="$linkx"><p class="bottomp"> Find More </a>';

What's the correct way of doing this?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • donglinxi1467 2013-12-06 09:07
    已采纳

    Example using SimpleXML and XPath

    <?php
    $doc = new SimpleXMLELement( data() );
    $fields = $doc->xpath('//form[@id="form2"]/field');
    
    foreach( $fields as $f) {
        printf('name=%s, type=%s, label=%s%s', $f['name'], $f['type'], $f['label'], PHP_EOL);
    }
    
    
    function data() {
    return <<< eot
    <data>
        <form id="form1"></form>
        <form id="form2">
            <field name="linkx" type="text" label="Find More Link" description="Link to more news" />
            <field name="linky" type="text" label="..." description="---" />
        </form>
        <form id="form3"></form>
    </data>
    eot;
    }
    

    prints

    name=linkx, type=text, label=Find More Link
    name=linky, type=text, label=...
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题