Sha*_* Md 10 html php comments
我正在尝试删除 html 文件中嵌入的所有注释
$data= file_get_contents($stream); <br>
$data = preg_replace('<!--*-->', '', $data); <br>
echo $data;
Run Code Online (Sandbox Code Playgroud)
我仍然收到所有评论 <!- bla bla bla -->
我做错了什么?
Sze*_*obe 13
// Remove unwanted HTML comments
function remove_html_comments($content = '') {
return preg_replace('/<!--(.|\s)*?-->/', '', $content);
}
Run Code Online (Sandbox Code Playgroud)
正如您可以在这里阅读:https://davidwalsh.name/remove-html-comments-php
我知道很多答案已经发布了。我已经尝试了很多,但对我来说,这个正则表达式适用于多行(在我的例子中是 40 行注释)HTML 注释删除。
$string = preg_replace("~<!--(.*?)-->~s", "", $string);
Run Code Online (Sandbox Code Playgroud)
干杯:)