gpt4 book ai didi

php - 如何修复格式错误的 XML?

转载 作者:可可西里 更新时间:2023-10-31 22:16:18 33 4
gpt4 key购买 nike

用 PHP 修复格式错误的 XML 文件的最佳做法是什么?例如 CDATA 部分包含非法字符。用正则表达式?或者执行一些 Linux 命令行工具?

最佳答案

Tidy

Tidy is a binding for the Tidy HTML clean and repair utility which allows you to not only clean and otherwise manipulate HTML documents, but also traverse the document tree.

// Specify configuration
$config = array(
'indent' => true,
'input-xml' => true,
'output-xml' => true,
'wrap' => false);
// Tidy
$tidy = new tidy;
$tidy->parseFile('sample.xml', $config);
$tidy->cleanRepair();
// Output
echo $tidy;

关于php - 如何修复格式错误的 XML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3797100/

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