PHP Preg-Replace more than one underscore

前端 未结 8 1400
难免孤独
难免孤独 2020-12-17 03:22

How do I, using preg_replace, replace more than one underscore with just one underscore?

8条回答
  •  不知归路
    2020-12-17 04:23

    The + operator matches multiple instances of the last character (or capture group).

    $string = preg_replace('/_+/', '_', $string);
    

提交回复
热议问题