# wechat-html2json **Repository Path**: freyo/wechat-html2json ## Basic Information - **Project Name**: wechat-html2json - **Description**: Convert HTML to WeChat Mini Program Rich Text Nodes - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-07-27 - **Last Updated**: 2021-04-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # wechat-html2json Convert HTML to WeChat Mini Program Rich Text Nodes # Install ``` composer require freyo/wechat-html2json ``` # Usage ```php use Freyo\WeChatMiniProgram\Utils\RichTextParser; $parsed = RichTextParser::loadHTML($HTML) ->setElementNodeHook(function ($node, $childNode) { // remove span node if ($childNode->nodeName === 'span') { return $node['children']; } // add width to img node if ($childNode->nodeName === 'img') { $node['attrs']['width'] = '100%'; } return $node; }) ->setTextNodeHook(function ($node, $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() var_dump($parsed); ```