duanqiao8925 2016-07-27 14:18
浏览 31
已采纳

将标签从xml文件读入php数组

I am trying to display a list of all the tags in a XML file. But I can't seem to do it. [

This is the XML I am tying to read the tags from: http://i.stack.imgur.com/9bYHi.png

If someone knows a way to keep the tree struckture of the xml file and trasfer it into an array. That would be really helpfull.

My question is different because I don't know the contents of the xml file. My image is just an example. I am looking for a solution that reads all the tags from an xml file and also keeps the tree structure when putting it in an array.

  • 写回答

1条回答 默认 最新

  • doudaochu1699 2016-07-27 14:25
    关注

    I always use xml_parser_create, so you could do the following

    $yourxmlfile = "pathto/yourfilename.xml";
    $xmldata = file_get_contents($yourxmlfile);
    $p = xml_parser_create();
    xml_parse_into_struct($p, $xmldata, $vals, $index);
    xml_parser_free($p);
    
    print_r($vals);
    

    that should print the xml structure as an array, see http://php.net/manual/en/function.xml-parse-into-struct.php for more info about it

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

报告相同问题?

悬赏问题

  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,