Xml についてはあまり説明しません。PHP では XML を操作するためのメソッドも用意されています。domdocment、simplexml、xmlwriter などがあります。今回は、simplexml の読み込み方法について説明します。 simplexml. XML ファイルまたは文字列を取得して解析します
1. XML 文字列とファイルを生成します
<?php
header("Content-type: text/html; charset=utf-8");
$xml=new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><UsersInfo />');
$item=$xml->addchild("item");
$item->addchild("name","冯绍峰");
$item->addchild("age","30");
$item2=$xml->addchild("item");
$item2->addchild("name","潘玮柏");
$item2->addchild("age","29");
$item2->addAttribute("id","02");
header("Content-type: text/xml");
echo $xml->asXml();
$xml->asXml("student.xml");
?>
以上がPHP XML の解析と生成のための SimpleXML の使用の概要の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。