0

Let's say i have the string $urlname = "pine-tree-tshirt--green-xs"

I want my result to be $urlname = "pine-tree-tshirt-green-xs"

I don't want to remove all duplicates characters (for example tree, the e should be duplicated here), only the - character.

Raluca Albu
  • 332
  • 2
  • 7
  • 6
    Possible duplicate of [Remove duplicates of certain characters from string](https://stackoverflow.com/questions/9350851/remove-duplicates-of-certain-characters-from-string) – Masivuye Cokile Dec 19 '18 at 10:43
  • 3
    `str_replace("--","-",$urlname);` – Jeff Dec 19 '18 at 10:44
  • @MasivuyeCokile thanks, it is a duplicate, and I found there the answer $characterwanted = array("-"); $expression = join('|', $characterwanted); $result = preg_replace('/(' . $expression . ')\1+/', '$1', $urlname); – Raluca Albu Dec 19 '18 at 10:59

0 Answers0