PHP xml 파일 읽기

1 개요[ | ]

PHP xml 파일 읽기
PHP simplexml_load_file()
  • moldb.xml
<?xml version="1.0"?>
<moldb>
  <molecule>
    <name>Alanine</name>
    <symbol>ala</symbol>
    <code>A</code>
    <type>hydrophobic</type>
  </molecule>
  <molecule>
    <name>Lysine</name>
    <symbol>lys</symbol>
    <code>K</code>
    <type>charged</type>
  </molecule>
</moldb>
  • read_xml_file.php
<?php
$obj = simplexml_load_file('moldb.xml');
print_r( $obj );
  • 실행결과
[root@zetawiki ~]# php read_xml_file.php 
SimpleXMLElement Object
(
    [molecule] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [name] => Alanine
                    [symbol] => ala
                    [code] => A
                    [type] => hydrophobic
                )

            [1] => SimpleXMLElement Object
                (
                    [name] => Lysine
                    [symbol] => lys
                    [code] => K
                    [type] => charged
                )

        )

)

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}