dneustadt/html-tag-replace
Composer 安装命令:
composer require dneustadt/html-tag-replace
包简介
Replace and enhance markup tags and/or attributes
README 文档
README
a helper to replace and enhance html tags and their attributes.
Features
- Append, prepend and switch tags.
- Add custom attributes to tags
- Switch, clone or remove attributes.
Usage
Create an Instance of HtmlTagReplace passing existing markup.
Use replaceTag method of said instance passing the following arguments:
searchName of the tag to be replacedreplaceName of the new tagclosingTag(bool, default: false) defines whether searched tag has closing tagargumentsReplace(array) key-value pairs (search => replace) of attributes to be replaced. Multidimensional (search => array) to clone value into multiple arguments.argumentscustom arguments injectedappendinjected after targeted tagprependinjected before targeted tag
You can call the method compress to minify the markup.
Finally retrieve the altered markup calling getMarkup
Example
$markup = ' <img src="#" alt="foo"> <img src="#"> <div id="foo">bar</div> <em class="foo">bar</em> <input type="text" name="foo"> '; $replacer = new HtmlTagReplace($markup); echo $replacer->replaceTag( 'img', 'a', false, ['src' => 'href', 'alt' => false], 'title="show image"', 'show image</a>' )->replaceTag( 'div', 'article', true, ['id' => 'class'], null, null, '<hr>' )->replaceTag( 'em', 'strong', true )->replaceTag( 'input', 'input', false, ['name' => ['name', 'id']] )->compress()->getMarkup();
will result in (not minified for readability):
<a title="show image" href="#">show image</a> <a title="show image" href="#">show image</a> <hr><article class="foo">bar</article> <strong class="foo">bar</strong> <input type="text" name="foo" id="foo">
Todos
- add more filter options for targeting tags
- optimize method for filtering and replacing arguments
- content manipulation
- synchronized replacement
统计信息
- 总下载量: 114
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-12-30