PHP:如何使用tidy缩小字符串而不修复它
我只想在保存到DB之前删除html字符串中的注释和空白。我不希望它被修理和添加头标签等PHP:如何使用tidy缩小字符串而不修复它,php,tidy,Php,Tidy,我只想在保存到DB之前删除html字符串中的注释和空白。我不希望它被修理和添加头标签等 我花了几个小时搜索这个,但找不到任何东西,有人能告诉我我需要什么配置,哪个php tidy函数只是“缩小”,而不是尝试从html字符串生成有效的html文档吗?下面的示例可能会帮到你: <?php function html2txt($document){ $search = array('@<script[^>]*?>.*?</script>@si', // Strip
我花了几个小时搜索这个,但找不到任何东西,有人能告诉我我需要什么配置,哪个php tidy函数只是“缩小”,而不是尝试从html字符串生成有效的html文档吗?下面的示例可能会帮到你:
<?php
function html2txt($document){
$search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA
);
$text = preg_replace($search, '', $document);
return $text;
}
?>
你可以在上获得更多信息。你能试试这个吗
下面的函数用于删除不需要的HTML注释和空白
function remove_html_comments_white_spaces($content = '') {
$content = preg_replace('~>\s+<~', '><', $content);
$content = preg_replace('/<!--(.|\s)*?-->/', '', $content);
return $content;
}
function remove\u html\u comments\u white\u spaces($content=''){
$content=preg_replace(“~>\s+/”,“$content”);
返回$content;
}
到目前为止你都试了些什么?这里的两个最重要的答案会有帮助吗?