2012-05-08 52 views
1

我目前正在翻译大数据集(大约7000行)。此数据集包含英文短语,但也包含HTML标记,已通过Google翻译转换为荷兰语。删除HTML标记内的空白

但是,在查看生成的翻译时,Google Translate还通过添加空格来对HTML标签进行加扰。我想删除翻译文件中HTML标记内的所有无效空白。例如:

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

应该变成:

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

是否有一个正则表达式,可以让这一切成为可能?

+0

你不想删除_all_空格,你想删除'='和'>'前面的多余空格。 –

+0

'$ yourString = str_replace(“<”,“<”,$ yourString);',重复? – Bobby

+3

使用HTML Tidy“修正”标记。 http://php.net/manual/en/book.tidy.php –

回答

1
$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);