PHP基础-如何读取xml内容变成table
发布日期:2021-05-06 21:18:24 浏览次数:40 分类:技术文章

本文共 1503 字,大约阅读时间需要 5 分钟。

1.xml

虾米大王
22
计算机
虾米小王
21
网络管理

2.php

m_char = $ch; } function parse($xmlFile) { if(function_exists('simplexml_load_file')) { $xml = simplexml_load_file($xmlFile); } elseif(function_exists('file_get_contents')) { $xml = file_get_contents($xmlFile); $xml = new SimpleXMLElement($xml); } elseif(function_exists('fopen')) { $handle = fopen($xmlFile,'r'); $xml = ""; while(!feof($handle)) { $xml .= fread($handle,8192); } fclose($handle); $xml = new SimpleXMLElement($xml); } else { $xml = false; } return $xml; }}function xmlTable($content){ $header = "姓名年龄工作"; $body = ""; foreach ($content as $k => $v) { $body .= "".($v->name)."".($v->age)."" .($v->job).""; } echo "
".$header.$body."
";}function nodecodeTable($content){ $header = "姓名年龄工作"; $body = ""; foreach ($content as $k => $v) { $body .= "".($v->name)."".($v->age)."".($v->job).""; } echo "
".$header.$body."
";}$xFile = "1.xml";$xml = new xml('gb2312');$xml_content = $xml->parse($xFile);xmlTable($xml_content);nodecodeTable($xml_content);

 

上一篇:PHP基础-类的静态变量的读取
下一篇:PHP基础-如何使用DOMDocument读取内容

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2025年03月10日 22时40分24秒