2013-05-08 25 views
-1

例如,我想将字符串There are 4,000 bugs, fix them!替换为There are 4000 bugs, fix them!如何删除数字之间的逗号而不是PHP中的字母

注意第一个逗号被删除,但第二个逗号被保留。

+0

我想谷歌在PHP字符串解析功能你会发现许多方法来做到这一点。正则表达式是最好的,但可能会很棘手的学习。还有其他方法取决于你在做什么。 – rncrtr 2013-05-08 05:46:41

回答

4
preg_replace('/([0-9]),([0-9])/', '\\1\\2', 'There are 4,000 bugs, fix them!'); 
2

试试这个正则表达式:

/(\d+)(,)(\d+)/$1$3/ 

只是为了防止downvotes这里propper PHP:

preg_replace('/(\d+)(,)(\d+)/', '\\1\\3', $input_string); 
+0

我喜欢这个答案中的'\ d',但由于它的格式,您的示例在PHP中不起作用。 ^^ – Jon 2013-05-08 05:56:45

+1

我将它添加为php代码:-) – rekire 2013-05-08 06:46:11

0

试试这个

$str = "There are 4,000 bugs, fix them!"; 
$a = preg_replace('#(?<=\d),(?=\d)#', '', $str); 
print_r($a); 
相关问题