1
次のコードを使用してhtml内の空白を削除しています。私はタグ間の空白を削除したいだけです。コードは、すべての空白を置き換えるの下しかしHTML内のタグ間の空白を削除します
すなわちは「>」との間のすべての空白を削除し、「<」
//read the entire string
$str=file_get_contents('sample.txt');
//replace all white spaces
$str=str_replace("\n", "",$str);
$str=str_replace("\t", "",$str);
$str=str_replace(" ", "",$str);
//write the entire string
file_put_contents('sample.txt', $str);
あなたはhttp://php.net/manual/en/class.domdocument.php#domdocument([ 'のPreserveWhitespace = false'を]で' DomDocument'を使用することができます.props.preservewhitespace)さらに、[ここにある]に関する質問(http://stackoverflow.com/questions/7997936/how-do-you-format-dom-structures-in-php)。 – Jan
あなたはきちんとしたものを使うこともできます –
あなたは空白を取り除きたいと思っていますし、どの段階で何か具体的なことを推薦するのは難しいですね。正規表現は良い方法ではありませんが(http: //stackoverflow.com/q/1732348/17300)。私はダニエルが言及したように、きちんとした/ jTieyを使用しました。 –