yyxx9988 / html-wxml-converter
一个可以将HTML转换为wxml并反向转换的PHP库。
v1.0.0
2017-03-13 02:40 UTC
Requires (Dev)
- phpunit/phpunit: ^5.7
This package is not auto-updated.
Last update: 2024-09-18 20:55:25 UTC
README
一个可以将HTML转换为wxml并反向转换的PHP库。
需求
- PHP >= 5.4
安装
$ composer require "yyxx9988/html-wxml-converter"
使用方法
use \yyxx9988\mlconverter\Converter; $converter = new Converter(); $converter->setHtml(' <div> <a>...</a> <p><img src="..."></p> </div> '); echo $converter->convert(); // result <view data-htmltag="div"> <view data-htmltag="a">...</view> <view data-htmltag="p"><image src="..."></image></view> </view>
自定义
- 默认支持的标签
[ 'p' => 'view', 'h1' => 'view', 'h2' => 'view', 'h3' => 'view', 'h4' => 'view', 'h5' => 'view', 'h6' => 'view', 'ul' => 'view', 'ol' => 'view', 'li' => 'view', 'div' => 'view', 'nav' => 'view', 'pre' => 'view', 'code' => 'view', 'menu' => 'view', 'aside' => 'view', 'header' => 'view', 'footer' => 'view', 'legend' => 'view', 'section' => 'view', 'article' => 'view', 'caption' => 'view', 'details' => 'view', 'summary' => 'view', 'menuitem' => 'view', 'blockquote' => 'view', 'i' => 'text', 'b' => 'text', 's' => 'text', 'u' => 'text', 'big' => 'text', 'del' => 'text', 'sub' => 'text', 'sup' => 'text', 'ins' => 'text', 'font' => 'text', 'mark' => 'text', 'time' => 'text', 'span' => 'text', 'center' => 'text', 'strong' => 'text', 'strike' => 'text', ];
- 自定义特殊标签
$converter = new Converter(); // add a tag $converter->addHtmlTags('xxx', 'view'); // change a tag $converter->setHtmlTags('li', 'text'); // remove a tag $converter->removeHtmlTags('article'); echo $converter->convert();
许可证
MIT