1

DBに保存する前に、HTML文字列からコメントと空白を削除したいだけです。直してほしくないのでヘッドタグ等付けます。

これを何時間も探しましたが、何も見つかりません。これを行った人が、必要な構成と、どのphp tidy関数が単に「縮小」され、html文字列から有効なhtmlドキュメントを作成しようとしないかを教えてもらえますか?

4

2 に答える 2

0

以下の例はあなたを助けるかもしれません:

<?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;
}
?> 

詳細については、http://php.net/manual/en/function.strip-tags.phpを参照してください。

于 2013-11-03T08:43:36.807 に答える
0

これを試してみませんか?

以下の関数は、不要な HTML コメントと空白を削除するために使用されます。

      function remove_html_comments_white_spaces($content = '') {    

                  $content = preg_replace('~>\s+<~', '><', $content);
                  $content = preg_replace('/<!--(.|\s)*?-->/', '', $content);

            return $content;
        }

タグを削除したい場合でも、PHP 組み込み関数 strip_tags(); を使用できます。

于 2013-11-03T09:01:07.367 に答える