删除另一个字符之前的一个字符

问题描述

我需要在每个右括号,之前删除逗号)

示例字符串:

$string = "('abc','def','gah',),('qwe','rty','yui',)"

我尝试了多次结合substr,str_replace。只会给我错误的结果。

您能帮我吗?

解决方法

您需要将",)"替换为")"

$string = "('abc','def','gah',),('qwe','rty','yui',)";
$string = str_replace(",)",")",$string);
,

您可以像 cf push