1
xmlをオブジェクトに変換すると、すべてがprint_r($result);
に従って問題なく表示されます。しかし、私は$result->title
を使用する場合は、オブジェクトの代わりの文字列を返し、$result->documents
をループするとき、それは本当に奇妙な取得します。..PHP - simplexml_load_stringが期待どおりに動作しない
$xml = '<return>
<id>65510</id>
<title>SMART</title>
<info/>
<documents>
<name>file_1.pdf</name>
<path>http://www.domain.com/documents/file_1.pdf</path>
</documents>
<documents>
<name>file_2.pdf</name>
<path>http://www.domain.com/documents/file_2.pdf</path>
</documents>
<documents>
<name>file_3.pdf</name>
<path>http://www.domain.com/documents/file_3.pdf</path>
</documents>
</return>';
$result = simplexml_load_string($xml);
print_r($result); /* returns:
SimpleXMLElement Object
(
[id] => 65510
[title] => SMART
[info] => SimpleXMLElement Object
(
)
[documents] => Array
(
[0] => SimpleXMLElement Object
(
[name] => file_1.pdf
[path] => http://www.domain.com/documents/file_1.pdf
)
[1] => SimpleXMLElement Object
(
[name] => file_2.pdf
[path] => http://www.domain.com/documents/file_2.pdf
)
[2] => SimpleXMLElement Object
(
[name] => file_3.pdf
[path] => http://www.domain.com/documents/file_3.pdf
)
)
)
*/
$_VALUE['title'] = $result->title;
print_r($_VALUE); /* returns:
Array
(
[title] => SimpleXMLElement Object
(
[0] => SMART
)
)
*/
foreach ($result->documents as $key=>$value) {
echo $key . "<br/>";
} /* returns:
documents
documents
documents
instead of returning:
1
2
3
*/
私はインデックス1,2,3を持つ配列であることを文字列と$result->documents
を返すために$result->title
を必要としています。
OKと、私はphpmailerの中でこれらの値を使用し、それがエラースローされます:致命的なエラー:キャッチされない例外」を例外 'メッセージ付き' 'SimpleXMLElement'のシリアライゼーションは許可されていません。 ' – Totallama
OK'内部的にはすべて 'SimpleXMLElement'なので、大文字と小文字のデータを 'string'と入力する必要があります。' echo(string)$ result-> title ; ' –
そして、アレイを試して? – Totallama