Kazi Lotus
Kazi Lotus

Reputation: 182

What am I Doing wrong with str_replace ()?

Here is the HTML Code :

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

And this is the PHP Code :

//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);

What am I doing wrong ? Any help would be appreciated :)

~Kazilotus

Upvotes: 0

Views: 101

Answers (1)

Mark Parnell
Mark Parnell

Reputation: 9200

Your HTML is using XHTML syntax: <img ... /> but your PHP is looking for HTML syntax: <img ... >. You need to make up your mind which to use and stick with it.

For example,

$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);

Should be:

$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);

In your sample code.

Upvotes: 5

Related Questions