Jeremy Karlsson
Jeremy Karlsson

Reputation: 1089

PHP replace all

I have this in JavaScript:

msg = msg.replace(/(:\)|=\)|:-\)|\(:)/gi, "<img src='img/ei/1.png' class='ei' />");

Is there a similar way I can do that, but in PHP?

Thanks in advance, enji

Upvotes: 1

Views: 6948

Answers (2)

Shai Mishali
Shai Mishali

Reputation: 9382

If i understand correctly you are trying to replace instances of the :\ smiley with an image. You could do something like this:

<?php
    $str = "Hey there :)";

    str_replace(
      array(":)", "=)", ":-)", "(:"), 
      "<img src='img/ei/1.png' class='ei' />", 
      $str);
?>

Shai.

Upvotes: 3

deejayy
deejayy

Reputation: 770

Exactly the same way:

$msg = preg_replace('/(:\)|=\)|:-\)|\(:)/i', "<img src='img/ei/1.png' class='ei' />", $msg);

Upvotes: 5

Related Questions