2012-05-08 113 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);