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

What I want


Hello! I want to replace :)with smile.pngand :))by laugh.png.

Problem


the script finds :)inside :)), therefore it is laugh.pngnot displayed, only smile.png+)

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


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

Some other regular expressions I've tried:

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

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

But nothing wants to work that I tried.

+3
source share
4 answers

For :) - (:\)(?!\)))

Then

For :)) - (:\)\))

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

Order is important.

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

php.net str_replace: " (, ), ereg_replace() preg_replace()."

+2

?

:)) laungh.png, :) smile.png

0

Source: https://habr.com/ru/post/1757049/


All Articles