PHP REGEX: Problem with Smiley `:)` and `:))`

What I want


Hi! I want to replace :) to smile.png and :)) to laugh.png.

The problem


The script finds :) inside :)) so laugh.png is not shown, only smile.png+)

This is what I have tried so far for :)):


preg_replace("/:)+(?!))/i",$image, $string))

Some other regexes what I tried:

"/\:\)+(?=\))/i"

"/\:+(?=\)\))/i"

But nothing want's to work what I tried yet.

Answers


For :) – (:\)(?!\)))

Then

For :)) – (:\)\))


str_replace(array(":))", ":)"), array("laugh.png", "smile.png"), $string);

The order is important.


$string = str_replace(':))', 'laugh.png', $string);
$string = str_replace(':)', 'smile.png', $string);

php.net on str_replace: "If you don't need fancy replacing rules (like regular expressions), you should always use this function instead of ereg_replace() or preg_replace()."


Why don't you do a simple text replace?

First :)) to laungh.png, then :) to smile.png


Need Your Help

"path" not a valid property for Image.source

c# wpf pixelsense

I'm trying to change the background image set by xaml this way:

Which version of Make to use for Java?

java makefile

I have make (Windows SDK), nmake (Visual Studio) and make (CodeGear)