gpt4 book ai didi

php - 将 xml 传递给 php 函数

转载 作者:行者123 更新时间:2023-12-04 19:28:27 26 4
gpt4 key购买 nike

我正在考虑将一个 XML 字符串传递给一个函数,然后我将返回父节点及其值。

举个例子:

$xml = "<Student><Name>Jee Pee</Name><Age>16</Age></Student>";
runXmltoStr($xml);

function runXmltoStr($xml)
{
// This is where I can't figure out where to start
// In my mind, I do have this output
//
// Student
// Name: Jee Pee
// Age: 16
}

最佳答案

您应该使用 XML 解析器,例如 SimpleXML :

$xml_node = simplexml_load_string($xml);
$xml_node->Name; // Jee Pee
$xml_node->Age; // 16

关于php - 将 xml 传递给 php 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8546573/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com