💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
~~~ /** * 去除字符串中所有html代码(格式化代码html) */ if ( ! function_exists('clearHtml')) { function clearHtml($content) { $content = preg_replace("/<a[^>]*>/i", "", $content); $content = preg_replace("/<\/a>/i", "", $content); $content = preg_replace("/<p(.*?)>/i", "<p>", $content);//去除p标签里的样式 $content = preg_replace("/<p><\/p>/i", "", $content); $content = preg_replace("/<p> <\/p>/i", "", $content); $content = preg_replace("/<p><br><\/p>/i", "", $content); $content = preg_replace("/<p><br\/><\/p>/i", "", $content); $content = preg_replace("/<p><br \/><\/p>/i", "", $content); $content = preg_replace("/<div[^>]*>/i", "", $content); $content = preg_replace("/<\/div>/i", "", $content); //$content = preg_replace("/<!--[^>]*-->/i", "", $content);//注释内容 $content = preg_replace("/<!--(.*?)-->/i", "", $content);//注释内容 $content = preg_replace("/<style>(.*)<\/style>/i", '', $content);//去除样式 $content = preg_replace("/style=.+?\"/i", '', $content);//去除样式 $content = preg_replace("/style=.+?['|\"]/i", '', $content);//去除样式 $content = preg_replace("/class=.+?['|\"]/i", '', $content);//去除样式 //$content = preg_replace("/id=.+?['|\"]/i", '', $content);//去除样式 $content = preg_replace("/lang=.+?['|\"]/i", '', $content);//去除样式 $content = preg_replace("/width=.+?['|\"]/i", '', $content);//去除样式 $content = preg_replace("/height=.+?['|\"]/i", '', $content);//去除样式 $content = preg_replace("/border=.+?['|\"]/i", '', $content);//去除样式 $content = preg_replace("/face=.+?['|\"]/i", '', $content);//去除样式 $content = preg_replace("/face=.+?['|\"]/", '', $content);//去除样式只允许小写正则匹配没有带 i 参数 $content = preg_replace("<fieldset(.*?)>", "div", $content); $content = preg_replace("</fieldset(.*?)>", "div", $content); $content = preg_replace("<voice(.*?)>", "span", $content); $content = preg_replace("</voice(.*?)>", "span", $content); $content = preg_replace("<section(.*?)>", "div", $content); //去除section标签 $content = preg_replace("</section(.*?)>", "div", $content); //去除section标签 $content = preg_replace("/<strong(.*?)>/i", "", $content);//去除加粗 $content = preg_replace("/<\/strong>/i", "", $content);//去除加粗 $content = preg_replace("/<script(.*?)>/i", "", $content); $content = preg_replace("/<\/script>/i", "", $content);//去除script $content = preg_replace("/<button(.*?)>(.*?)<\/button>/i", "", $content);//去除button //$content = preg_replace("/<\/button>/i", "", $content);//去除button $content = preg_replace('/<svg viewbox=(.*?)\/>/i', "", $content); $content = preg_replace('/<!\[CDATA(.*?)\]\]>/i', "", $content); $content = preg_replace("/<h1(.*?)>/i", "<p>", $content); $content = preg_replace("/<\/h1(.*?)>/i", "<\/p>", $content); $content = preg_replace("/<h2(.*?)>/i", "<p>", $content); $content = preg_replace("/<\/h2(.*?)>/i", "<\/p>", $content); $content = preg_replace("/<h3(.*?)>/i", "<p>", $content); $content = preg_replace("/<\/h3(.*?)>/i", "<\/p>", $content); $content = preg_replace("/<h4(.*?)>/i", "<p>", $content); $content = preg_replace("/<\/h4(.*?)>/i", "<\/p>", $content); $content = preg_replace("/(\xc2\xa0)/", '', $content); //去除全角空格 $content = str_replace("<b>", "", $content);//去除加粗 $content = str_replace("<\/b>", "", $content);//去除加粗 $content = str_replace("<u>", "", $content); $content = str_replace("<u >", "", $content); $content = str_replace("</u>", "", $content); $content = str_replace("<b >", "", $content); $content = str_replace("<b>", "", $content); $content = str_replace("</b>", "", $content); $content = str_replace(" ", "", $content); //$content = str_replace("\t", '', $content);//去除\t //$content = str_replace("\n", '', $content);//去除\n return $content; } } ~~~