freyo/wechat-html2json
Composer 安装命令:
composer require freyo/wechat-html2json
包简介
Convert HTML to WeChat Mini Program Rich Text Nodes.
README 文档
README
Convert HTML to WeChat Mini Program Rich Text Nodes
Install
composer require freyo/wechat-html2json
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);
统计信息
- 总下载量: 125
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-07-07