dongroufan6846 2015-07-31 10:08
浏览 12
已采纳

完全停止XML和PHP的复杂性

I have the following PHP code:

<?php
    $string = "
    <root>
    <row>
        <kod>1.1</kod>
        <kategorie>Title1</kategorie>
    </row>
    <row>
        <kod>1.2</kod>
        <kategorie>Title2</kategorie>
    </row>
</root>";

    $xml = simplexml_load_string($string);

    //print_r($xml);

    foreach($xml->children() as $item){
        echo $item->kod;
        echo "<BR />";
    }
?>

I saw no output, only two <BR />. I don't understand why. Is the fullstop in 1.1 the problem? Or is kod some keyword in PHP? It showed me only onetimes the output, but not again, but I changed nothing. If I write echo $item->kategorie; everything is OK. Thank you.

  • 写回答

1条回答 默认 最新

  • dozc58418381 2015-07-31 10:16
    关注

    echo $string, see view source and you will get invisible '?' in <code>

    <root>
    <row>
            <?kod>1.1</?kod>
            <kategorie>Title1</kategorie>
        </row>
        <row>
            <?kod>1.2</?kod>
            <kategorie>Title2</kategorie>
        </row>
    </root>
    

    Solution:

    I have researched much but didn't find a good solution. Since we know we are getting '?' in the xml, following would be helpful for temporary solution.

    $string = preg_replace(array('/<\?/', '/<\/\?/'), array('<', '</'), $string);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向