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

前端 未结 4 1078
别跟我提以往
别跟我提以往 2021-01-14 15:22

What I want


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

Th

相关标签:
4条回答
  • 2021-01-14 15:50
    str_replace(array(":))", ":)"), array("laugh.png", "smile.png"), $string);
    

    The order is important.

    0 讨论(0)
  • 2021-01-14 15:58

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

    Then

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

    0 讨论(0)
  • 2021-01-14 16:09
    $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()."

    0 讨论(0)
  • 2021-01-14 16:12

    Why don't you do a simple text replace?

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

    0 讨论(0)
提交回复
热议问题