Replace 2 commas separated by space with space using php

后端 未结 4 824
故里飘歌
故里飘歌 2021-01-17 06:10

Hi friends am trying to replace two commas separated by space with space using php. Here is my code

Suppose for example am having variable like

 $va         


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-17 06:11

    preg_replace('/(,\s?)+$/', '', "hello, welcome, , , ,");
    

    Basically, match every contiguous sequence of , until the end of the string.

    see https://regex101.com/r/rSp90e/1 for a demo.

提交回复
热议问题