simonschaufi/pretty-xml 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

simonschaufi/pretty-xml

最新稳定版本:3.0.0

Composer 安装命令:

composer require simonschaufi/pretty-xml

包简介

Library for pretty-printing XML

关键字:

README 文档

README

A tiny library for pretty printing XML, inspired purely from DomDocument's lack of ability to configure indent distance.

Latest Stable Version Total Downloads

Usage

Installation

The recommended way to install the extension is using Composer.

Run the following command:

composer require simonschaufi/pretty-xml

How to use

Prettify

To use, give it a badly indented (but well-formed and valid) XML string:

use PrettyXml\Formatter;

$formatter = new Formatter();
echo "<pre>" . htmlspecialchars($formatter->format('<?xml version="1.0" encoding="UTF-8"?><foo><bar>Baz</bar></foo>')) . "</pre>";

You can also change the size of the indent:

$formatter->setIndentSize(2);

And you can change the indent character:

$formatter->setIndentCharacter("\t");

Minify

use PrettyXml\Formatter;

$formatter = new Formatter();
echo htmlspecialchars($formatter->minify(<<<XML
<?xml version="1.0" encoding="UTF-8"?>
<foo>
    <bar>Baz</bar>
</foo>
XML));

// keep comments
echo htmlspecialchars($formatter->minify(<<<XML
<?xml version="1.0" encoding="UTF-8"?>
<foo>
    <!-- comment -->
    <bar>Baz</bar>
</foo>
XML, true));

Thanks

Thanks to vkBeautify for their algorithm.

统计信息

  • 总下载量: 78.58k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 22
  • 点击次数: 8
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 22
  • Watchers: 3
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04