簡體   English   中英

刪除 HTML 中標簽之間的空格

[英]Remove white spaces between tags in HTML

我正在使用以下代碼刪除 html 中的空格。 我只想刪除標簽之間的空格。 但下面的代碼替換了所有空格

IE 刪除“>”和“<”之間的所有空格

//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);

您需要使用正則表達式。

也許你可以使用這個:

$html = preg_replace('/\>\s+\</m', '><', $html);

在這里測試https://repl.it/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM