首先,字符串正在從XML文件中提取。str_replace的問題
有,我試圖取代一個特殊字符: '£'
當我使用str_replace函數像這樣:
$ability1 = str_replace("£", "", $ability);
這是什麼的var_dump顯示:
string(138) "Argothian Pixies can't be blocked by artifact creatures.�Prevent all damage that would be dealt to Argothian Pixies by artifact creatures."
一旦$ ability1被傳遞,wordpress將其插入帖子中。這是結果。
Argothian Pixies can’t be blocked by artifact creatures.
刪除 字符後的所有內容。
爲什麼當£應該是「」時,將£改變爲 。我不太確定我丟失的是什麼
是的,就是這樣。我前幾天讀過那篇文章,但它已經滑了我的頭腦,哈哈。 preg_replace導致它刪除所有內容,只留下特殊字符。結束使用: $ ability1 = utf8_decode($ ability); $ ability1 = str_replace(「£」,「」,$ ability1); $ ability1 = utf8_encode($ ability1); – 2012-04-04 13:30:15
對不起。表達中有一個「不」(^)。 – fragmentedreality 2012-04-04 13:47:55
**使用警告:**這段代碼引入了數據丟失。 – hakre 2012-06-15 16:18:37