simplexml_load_string
XML文字列をオブジェクトに変換します。
simplexml_load_string()関数は、よく形成されたXML文字列をオブジェクトに変換します。
XML文字列をオブジェクトに変換し、オブジェクトのキーと要素を出力します。
<?php $ note = <<< xml <ノート> <to> george </to> <from> john </from> <見出し>リマインダー</heading> <body>会議を忘れないでください!</body> </note> XML ; $ xml = simplexml_load_string ( $ note ) ; print_r ( $ xml ) ; ?>
インスタンスを実行します
XML文字列の各要素の出力データ:
<?php $ note = <<< xml <ノート> <to> george </to> <from> john </from> <見出し>リマインダー</heading> <body>会議を忘れないでください!</body> </note> XML ; $ xml = simplexml_load_string ( $ note ) ; echo $ xml- > to 。 "<br>" ; echo $ xml- > from 。 "<br>" ; echo $ xml- >見出し。 "<br>" ; echo $ xml- > body ; ?>
インスタンスを実行します
XML文字列に各子ノードの要素名とデータを出力します。
<?php
$ note = <<< xml
<ノート>
<to> george </to>
<from> john </from>
<見出し>リマインダー</heading>
<body>会議を忘れないでください!</body>
</note>
XML ;
$ xml = simplexml_load_string ( $ note ) ;
echo $ xml- > getName ( ) 。 "<br>" ;
foreach ( $ xml- > children ( ) as $ child )
{
echo $ child- > getname ( ) 。 ":" 。 $子供。 "<br>" ;
}
?>
インスタンスを実行します
simplexml_load_string (データ、クラス、オプション、 ns 、 is_prefix )
| パラメーター | 説明する |
|---|---|
| データ | 必須。よく形成されたXML文字列を指定します。 |
| クラス | オプション。新しいオブジェクトのクラス名を指定します。 |
| オプション | オプション。追加のLIBXMLパラメーターを指定します。オプションと1または0を指定して設定します(libxml_noblanks(1)などのtrueまたはfalse)。 考えられる値は次のとおりです。
|
| ns | オプション。名前空間プレフィックスまたはURIを指定します。 |
| is_prefix | オプション。ブール値を指定します。 NSがプレフィックスの場合、それは本当です。 NSがURIの場合、それは間違っています。 デフォルトはfalseです。 |