/**
* 删除指定标签
* @param array $tags 删除的标签
* @param string $str html字符串
* @param bool $type 是否保留标签的内容
* @return mixed
* @usage
* $str = 'Hello</p><p><img src="http://www.baidu.com" /></b><Video>';
*
* // echo strip_tags($str, '<img');
* echo $this->stripHtmlTags(array('b','p'),$str,true);
*/
public static function stripHtmlTags($str,$tags=['p','b'], $content=true)
{
$html = [];
if($content){
foreach ($tags as $tag) {
$html[] = "/(<(?:\/" .$tag. "|" .$tag. ")[^>]*>)/is";
}
}else{
foreach ($tags as $tag) {
$html[] = '/<' .$tag. '.*?>[\s|\S]*?<\/' .$tag. '>/is';
$html[] = '/<' .$tag. '.*?>/is';
}
}
$data = preg_replace($html, '', $str);
return $data;
}
blueidea
Recommended Posts
要在原文件名前加上前缀并实现文件的批量重命名,你可以根据你所使用的操作系统选择合适的脚本语言来编写脚本。以下是在不同操作系统上实现这一功能的示例: 在 Windows 上使用 PowerShell 在 macOS/Linux 上使用 Shell 脚本 在 Python 中使用 os 模块 注意事项 将上述脚本中的 folder_path 或 $folderPath 替换为你的文件夹路径,将 prefix 替换为你想要添加的前缀,然后运行脚本即可。