定制 masroore/html2text 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

masroore/html2text

最新稳定版本:0.0.1

Composer 安装命令:

composer require masroore/html2text

包简介

A PHP package to convert HTML into a plain text format

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Overview

masroore/html2text is a PHP package that converts a page of HTML into clean, easy-to-read plain ASCII text.

Installation

Requires PHP 8.0+

You can install the package via composer:

composer require masroore/html2text

Usage

Extract text from HTML:

use Kaiju\Html2Text\Html2Text; $converter = new Html2Text(); echo $converter->convert($html);

Callback functions

You are able to change process of formatting by providing callbacks in pre-processing, tag-replacing and post-processing:

# assign a pre-processing callback function. (transform href links) $converter->setPreProcessingCallback(fn (string $s) => preg_replace('%<\s*a[^>]*href=[\'"](.*?)[\'"][^>]*>([\s\S]*?)<\/\s*a\s*>%i', '$2 ($1)', $s)); # assign a tag-replacement callback function. (replace <li> tags) $converter->setTagReplacementCallback(fn (string $s) => preg_replace('/<\s*li[^>]*>/i', "\n- ", $s)); # post-processing hook $converter->setPostProcessingCallback(...); # process HTML echo $converter->convert($html);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Thank you for considering to contribute to Html2Text. All the contribution guidelines are mentioned here.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

Html2Text is an open-sourced software licensed under the MIT license.

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

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