gpt4 book ai didi

php - 获取 Xml 版本

转载 作者:行者123 更新时间:2023-12-04 16:45:00 25 4
gpt4 key购买 nike

我有一个 xml 文件,我想在 PHP 中获取版本和编码编号。

例如:

<?xml version="1.0" encoding="ISO-8859-1"?>
<from>John</from>

我想获取 PHP 的版本和编码信息。 (对于此示例 1.0 和 ISO-8859-1)

如何在 PHP 中获取它?

最佳答案

您可以使用 DOMDocument做这个。

$doc = new DOMDocument;
$doc->load('file.xml');
// or you can load the XML string
//$doc->loadXML('<?xml version="1.0" encoding="ISO-8859-1"?><from>John</from>');
$version = $doc->xmlVersion; // 1.0
$encoding = $doc->xmlEncoding; // ISO-8859-1

关于php - 获取 Xml 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7840313/

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