2012-09-05 321 views
1

我正在運行下面的腳本,它從XML Feed中獲取播放器的值。如果我以這種方式運行它取代了由E的E裏的代碼,PHP替換特殊字符

     $player = "Toré"; 
         echo "Player Before: $player <br />"; 
         $playerafter = strtr($player, $normalizeChars); 
         echo "Player After: $playerafter <br />"; 

但是,如果我用XML運行訂閱它不會改變

     $player = "$event->player"; 
         echo "Player Before: $player <br />"; 
         $playerafter = strtr($player, $normalizeChars); 
         echo "Player After: $playerafter <br />"; 

這裏是變量$ normalizeChars

$normalizeChars = array( 
     'Á'=>'A', 'À'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Å'=>'A', 'Ä'=>'A', 'Æ'=>'AE', 'Ç'=>'C', 
     'É'=>'E', 'È'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Í'=>'I', 'Ì'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ð'=>'Eth', 
     'Ñ'=>'N', 'Ó'=>'O', 'Ò'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 
     'Ú'=>'U', 'Ù'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 

     'á'=>'a', 'à'=>'a', 'â'=>'a', 'ã'=>'a', 'å'=>'a', 'ä'=>'a', 'æ'=>'ae', 'ç'=>'c', 
     'é'=>'e', 'è'=>'e', 'ê'=>'e', 'ë'=>'e', 'í'=>'i', 'ì'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'eth', 
     'ñ'=>'n', 'ó'=>'o', 'ò'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 
     'ú'=>'u', 'ù'=>'u', 'û'=>'u', 'ü'=>'u', 'ý'=>'y', 

     'ß'=>'sz', 'þ'=>'thorn', 'ÿ'=>'y' 
    ); 
+0

那麼問題是什麼?你有什麼問題? –

+0

'$ player =「$ event-> player」;'只會存儲:'Array-> player',而不是數組/對象中的值。 – hjpotter92

+0

如果我使用未加引號的版本,它仍然不起作用 – Somk

回答

-2

將xml強制轉換爲字符串。

$player = (string)$event->player; 
+0

'「$ event-> player」'**是一個字符串。 – Tchoupi