PHPで作成を行っています。
PEARのXML_Serializerを利用して、XMLをバースし結果を表示したいと考えています。
1つのxmlを利用するのは問題なく終わったのですが、複数のxmlをバースしたい場合の上手い方法が思い付きません。
===↓私が思いついた方法↓====================
$xmlData = 'ttp://example.com/data1.xml';
$xmlData2 = 'ttp://example.com/data2.xml';
$class_xml_uns = &new XML_Unserializer(array('parseAttributes' => true));
$class_xml_uns->unserialize(file_get_contents($xmlData));
$res_list = $class_xml_uns->getUnserializedData();
$class_xml_uns2 = &new XML_Unserializer(array('parseAttributes' => true));
$class_xml_uns2->unserialize(file_get_contents($xmlData2));
$res_list2 = $class_xml_uns2->getUnserializedData();
単純に2回バースするといった感じです。
何か同じ事を2回も3回も書かないといけないし、こんな事をしなくても出来るそうな気がして調べてはみたのですが、検索方法が下手なのか答えに行きつきませんでした。
ご教授とご指導のほど、宜しくお願い致します。
No.1ベストアンサー
- 回答日時:
配列でループさせると下記のようになります。
<?php
$xmlDatas = array(
'ttp://example.com/data1.xml',
'ttp://example.com/data2.xml'
);
$i=0;
foreach ($xmlDatas as $xmlData) {
$class_xml_uns = &new XML_Unserializer(array('parseAttributes' => true));
$class_xml_uns->unserialize(file_get_contents($xmlData));
$res_list[$i] = $class_xml_uns->getUnserializedData();
$i++;
}
?>
ループ後の格納先は、
$res_listが、$res_list[0]で、
$res_list2が、$res_list[1]です。
回答ありがとうございます。
最初、foreachかforでのループ処理…と考えたのですが上手くいきませんでした。
その時は[$i]がを入れていませんでした。
$iに1ずつ足してループさせればよかったんですね!!!
勉強になりました。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
- ・ゆるやかでぃべーと タイムマシンを破壊すべきか。
- ・歩いた自慢大会
- ・許せない心理テスト
- ・字面がカッコいい英単語
- ・これ何て呼びますか Part2
- ・人生で一番思い出に残ってる靴
- ・ゆるやかでぃべーと すべての高校生はアルバイトをするべきだ。
- ・初めて自分の家と他人の家が違う、と意識した時
- ・単二電池
- ・チョコミントアイス
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
XML_Serializerで複数のXMLの扱い
-
2次元配列の値の受け渡しについ...
-
テキストボックスの日本語をロ...
-
順位を付ける時のスコアの重複...
-
プルダウンメニューにDBの内容...
-
$a[0]='w';$a[1]='r';を1回で
-
HTTPのメッセージボディについ...
-
phpとmysqlで「あいまい検索」...
-
大切なPHP用語
-
クラス内での二次元配列への値...
-
CSVでアップロードしたデータの...
-
Resource id #3 と表示されま...
-
in_array関数について
-
String だと「 ByRef引数の型が...
-
配列をループでたくさん宣言し...
-
ヒアドキュメントの中のfor文
-
file_existsでファイル名の部分...
-
C言語でCSVファイルの行数を読...
-
cakephpでのトランザクション処...
-
PHP、CSVファイルの日本語デー...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
プルダウンメニューにDBの内容...
-
phpとmysqlで「あいまい検索」...
-
掲示板のあらし対策
-
しりとり 無限ループ?
-
file_get_contents()にて文字化け
-
PHP5の外部コマンド実行で、バ...
-
codeigniterのページネーション...
-
サイト名を取得するPHP
-
テキストボックスの日本語をロ...
-
多次元配列等の AND 検索について
-
Zend_Form_Element_Hash
-
XML_Serializerで複数のXMLの扱い
-
「ローマ字 -> ひらがな」へPHP...
-
cakephp2.6でfindを使い合計値...
-
$a[0]='w';$a[1]='r';を1回で
-
要素(文字列)から指定値を検索
-
クラス内での二次元配列への値...
-
順位を付ける時のスコアの重複...
-
pdfファイルの複数添付 引数の型
-
Resource id #3 と表示されま...
おすすめ情報