PHP シンプルな html dom を使用して、いくつかの html ファイルを編集しています。問題は、保存するとすべての改行が削除されることです。どうすればそれらを保存できますか? ありがとう
1 に答える
7
APIドキュメントにはそれらが表示されていませんがfile_get_html
、str_get_html
関数には追加の楽しいパラメーターがたくさんあります。開くだけsimple_html_dom.php
です:
function file_get_html(
$url, $use_include_path = false, $context=null, $offset = -1,
$maxLen=-1,
$lowercase = true,
$forceTagsClosed=true,
$target_charset = DEFAULT_TARGET_CHARSET,
$stripRN=true,
$defaultBRText=DEFAULT_BR_TEXT)
function str_get_html(
$str,
$lowercase=true,
$forceTagsClosed=true,
$target_charset = DEFAULT_TARGET_CHARSET,
$stripRN=true,
$defaultBRText=DEFAULT_BR_TEXT)
$stripRN
false に設定することもできますが、それ以外の場合は次のようになりsimple_html_dom->prepare()
ます。
//before we save the string as the doc... strip out the \r \n's if we are told to.
if ($stripRN) {
$str = str_replace("\r", " ", $str);
$str = str_replace("\n", " ", $str);
}
于 2012-07-03T06:54:49.173 に答える