Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何去除保留函数参数的函数参数列表中的空白?_Php_Regex_Preg Replace - Fatal编程技术网

Php 如何去除保留函数参数的函数参数列表中的空白?

Php 如何去除保留函数参数的函数参数列表中的空白?,php,regex,preg-replace,Php,Regex,Preg Replace,我想压缩代码,并想知道如何修改正则表达式,以去除逗号分隔的函数参数列表中的空白,保留逗号和参数。我正在慢慢缩小范围以匹配args和空格,但不知道如何编写正则表达式以使用清理后的字符串进行进一步处理 源字符串: function (arg1, arg2, arg3) 正则表达式: function\((\w+(\s*,\s*))+ 生成的字符串应如下所示 function(arg1,arg2,arg3) 你能告诉我怎么做吗?为什么不直接使用str_replace,例如$no_space=st

我想压缩代码,并想知道如何修改正则表达式,以去除逗号分隔的函数参数列表中的空白,保留逗号和参数。我正在慢慢缩小范围以匹配args和空格,但不知道如何编写正则表达式以使用清理后的字符串进行进一步处理

源字符串:

function (arg1, arg2, arg3)
正则表达式:

function\((\w+(\s*,\s*))+
生成的字符串应如下所示

function(arg1,arg2,arg3)

你能告诉我怎么做吗?

为什么不直接使用str_replace,例如$no_space=str_replace,$string@user1014412如果您有任何复杂的情况,上面的评论可以解决这个问题,然后发布它。为什么不使用标记器呢?