2013-04-26 60 views
0

下面是HTML代碼:我在做什麼錯str_replace()?

<a href="?loadurl=/search/Battlefield 3/1/99/0/"> 
    <img src="static/img/next.gif" border="0" alt="Next" /> 
</a> 

這是PHP代碼:

//Fix Icons 
$toremove = str_replace("next.gif\" border=\"0\" alt=\"Next\">", "dot.jpg\" border=\"0\" alt=\"Next\"><i class=\"icon-magnet\" style=\"color: #ffdd00;text-decoration: none;\"></i>", $toremove); 

我在做什麼錯? 任何幫助,將不勝感激:)

〜Kazilotus

+0

當你寫一個包含雙引號的字符串時,最好使用簡單的引號來避免每個雙引號內的轉義 – 2013-04-26 04:29:58

回答

5

你的HTML使用XHTML語法:<img ... />,但你的PHP正在尋找HTML語法:<img ... >。你需要下定決心使用它並堅持下去。

例如,

$toremove = str_replace("next.gif\" border=\"0\" alt=\"Next\">", "dot.jpg\" border=\"0\" alt=\"Next\"><i class=\"icon-magnet\" style=\"color: #ffdd00;text-decoration: none;\"></i>", $toremove); 

應該是:

$toremove = str_replace("next.gif\" border=\"0\" alt=\"Next\" />", "dot.jpg\" border=\"0\" alt=\"Next\"><i class=\"icon-magnet\" style=\"color: #ffdd00;text-decoration: none;\"></i>", $toremove); 

在你的示例代碼。

+0

是的,Thanx :) 那麼愚蠢的我沒注意到。 – 2013-04-26 04:17:52