matejch / html_helpers
用于删除元素和内容,以及提取文件路径的辅助类
1.0.1
2022-06-17 10:29 UTC
Requires
- php: >=7.2.0
- ext-dom: *
Requires (Dev)
- phpunit/phpunit: ^8.5
README
两个PHP辅助类,用于删除HTML标签和提取文件路径
在您的项目中安装
composer require matejch/html_helpers "^1.0.0"
class HtmlTagRemover
使用HtmlTagRemover
类,您可以从HTML字符串中删除指定的HTML标签及其内容
示例:根据名称删除标签
$service = new HtmlTagRemover($htmlString); service->removeTags(['a','img']);
示例:根据属性内容删除标签
$service = new HtmlTagRemover($htmlString); $service->removeTags(['a' => 'href[files]']); /** remove 'a' tags where href attribute contains `files` substring and span elements contains class with `test` string */ $service->removeTags(['a' => 'href[files]','span' => 'class[test]']);
class HtmlFileExtractor
我创建了此类,因为我需要在发送邮件之前从HTML中提取文件路径,并将其作为附件添加
此类可以自动从img或a标签中返回源代码
也可以从自定义标签或属性中返回
示例:从img和a标签中获取文件路径
$service = new HtmlFileExtractor($htmlString); /** return files as array of strings directly from href and src */ $service->getFiles(['img','a'])
示例:从其他标签或指定属性中获取文件路径
/** return files as array of strings from class attributes of span elements */ $service->getFiles(['span' => 'class']) $service->getFiles(['span' => 'class','img'=>'alt']) /** return files as array of strings from class attributes of span elements, * where class contains substring 'es' and from alt attribute of image tags */ $service->getFiles(['span' => 'class[es]','img'=>'alt'])
从您的项目中移除软件包
composer remove matejch/html_helpers