2013-06-05 117 views
0

我從網站獲取數據並保存到xml文件。我想要替換所有的土耳其字符,因爲如果沒有,當我從XML訪問數據時,我會變得奇怪的字符。轉換土耳其字符

我用這個代碼

$html = str_replace("ç", "Bccedil;", $html); 
$html = str_replace("Ç", "BCcedil;", $html); 
$html = str_replace("ö", "Bouml;" , $html); 
$html = str_replace("Ö", "BOuml;" , $html); 
$html = str_replace("ý", "B#305;" , $html); 
$html = str_replace("Ý", "B#304;" , $html); 
$html = str_replace("ü", "Buuml;" , $html); 
$html = str_replace("Ü", "BUuml;" , $html); 
$html = str_replace("ð", "B#287;" , $html); 
$html = str_replace("Ð", "B#286;" , $html); 
$html = str_replace("þ", "B#351;" , $html); 
$html = str_replace("Þ", "B#350;" , $html); 

$myFile = "test.xml"; 
$fh = fopen($myFile, 'w+') or die("can't open file"); 
fwrite($fh, $html); 
fclose($fh); 

很是怪異,沒有什麼此代碼後改變。如果我想將'a'替換爲'c',它可以工作。但對於土耳其人來說,它不起作用。

數據獲取:

伊斯坦布爾Taksim'debaşlayan已經蒙古包sathınayayılanolaylar

當我訪問:

ÝstanbulTaksim'debaþlayan已經蒙古包sathýnayayýlanolaylar

+0

可以粘貼在你的帖子一些土耳其句話時,要做到這一點?並呼籲'str_replace函數之前也貼上所謂的奇怪字符 –

+0

你確定這些字符是不是已經破碎'? – enenen

+0

@Jerin我更新了我的問題。 – abby

回答

0

您可以嘗試創建XmlDocument的

$dom = new DOMDocument('1.0', 'utf-8'); 
+0

我要在哪裏使用$ dom? – abby

+0

分享您的代碼,我不確定您是否正在讀取XML文檔到DOMDocument –

+0

我添加了關於將數據保存到xml的代碼 – abby