PHPackages                             freyo/wechat-html2json - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. freyo/wechat-html2json

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

freyo/wechat-html2json
======================

Convert HTML to WeChat Mini Program Rich Text Nodes.

0.1.1(6y ago)71251MITPHP

Since Jul 7Pushed 2y agoCompare

[ Source](https://github.com/freyo/wechat-html2json)[ Packagist](https://packagist.org/packages/freyo/wechat-html2json)[ RSS](/packages/freyo-wechat-html2json/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

wechat-html2json
================

[](#wechat-html2json)

Convert HTML to WeChat Mini Program Rich Text Nodes

Install
=======

[](#install)

```
composer require freyo/wechat-html2json

```

Usage
=====

[](#usage)

```
use Freyo\WeChatMiniProgram\Utils\RichTextParser;

$parsed = RichTextParser::loadHTML($HTML)
    ->setElementNodeHook(function (array $node, \DOMNode $childNode) {
        // remove span node
        if ($childNode->nodeName === 'span') {
            return $node['children'];
        }
        // add width to img node
        if ($childNode->nodeName === 'img') {
            $node['attrs']['width'] = '100%';
        }
        // modify origin DOMElement
        // FOR toHTML() ONLY
        if ($childNode->nodeName === 'a') {
            $childNode->setAttribute('target', '_blank');
        }
        return $node;
    })
    ->setTextNodeHook(function (array $node, \DOMNode $childNode) {
        // remove text node
        if (strpos($childNode->textContent, 'KeyWord') !== false) {
            return null;
        }
        // replace keywords
        $node['text'] = str_replace(
            'keyword', 'KEYWORD', $childNode->textContent
        );
        return $node;
    })
    ->toJSON(); // or toArray() or toHTML()

var_dump($parsed);
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

2506d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13034231?v=4)[freyo](/maintainers/freyo)[@freyo](https://github.com/freyo)

---

Top Contributors

[![freyo](https://avatars.githubusercontent.com/u/13034231?v=4)](https://github.com/freyo "freyo (10 commits)")

### Embed Badge

![Health badge](/badges/freyo-wechat-html2json/health.svg)

```
[![Health](https://phpackages.com/badges/freyo-wechat-html2json/health.svg)](https://phpackages.com/packages/freyo-wechat-html2json)
```

###  Alternatives

[alexsabur/orchid-editorjs-field

A orchid editorjs field

1327.4k](/packages/alexsabur-orchid-editorjs-field)[joungkyun/ereg-extension-wrapper

pure PHP EREG extension wrapper

102.5k](/packages/joungkyun-ereg-extension-wrapper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
