删除 HTML 标记中的空格


Remove whitespace inside HTML tags

我目前正在翻译一个大数据集(大约7000行)。该数据集包含英语短语和HTML标签,已使用谷歌翻译翻译成荷兰语。

但是,在审查生成的翻译时,谷歌翻译还通过添加空格来打乱HTML标签。我想删除翻译文件中 HTML 标签内的所有无效空格。例如:

this is a test. < a href = "hello.php" >test</ a>;

应该变成:

this is a test. <a href="hello.php">test</a>;

有没有正则表达式可以做到这一点?

$text = str_replace("< ", "<", $text);
$text = str_replace("> ", ">", $text);
$text = str_replace(" <", "<", $text);
$text = str_replace(" >", ">", $text);
$text = str_replace("= ", "=", $text);
$text = str_replace(" =", "=", $text);
$text = str_replace("'/ ", "'/", $text);