Home > Backend Development > PHP Tutorial > 一个关于正则去除小数点的问题,请大侠指教

一个关于正则去除小数点的问题,请大侠指教

WBOY
Release: 2016-06-23 13:53:14
Original
1351 people have browsed it

$a = 'aaa,bbb,ccc,"eee,ccc,sss,ppp",dddd,iiii,cccc';
Copy after login

如果碰到这种类型的字符串,我怎么才能使用正则来替换双引号里面的逗号呢?(注:双引号里面有几个逗号不是确定的,上面的只是列子)


回复讨论(解决方案)

在线等,请大侠来指点。

$a = 'aaa,bbb,ccc,"eee,ccc,sss,ppp",dddd,iiii,cccc';echo preg_replace_callback('/".+?"/', function($r) { return str_replace(',', ' ', $r[0]);}, $a);
Copy after login
aaa,bbb,ccc,"eee ccc sss ppp",dddd,iiii,cccc

$a = 'aaa,bbb,ccc,"eee,ccc,sss,ppp",dddd,iiii,cccc';$new=preg_replace('/"(.+?)"/ies',"replace('\\1')",$a);echo $new;//aaa,bbb,ccc,"eeecccsssppp",dddd,iiii,ccccfunction replace($str){	$return=str_replace(',','',$str);	return '"'.$return.'"';}
Copy after login

$a = 'aaa,bbb,ccc,"eee,ccc,sss,ppp",dddd,iiii,cccc';echo preg_replace('/(?<=")(.+?)(?=")/e', 'str_replace(",", " ", "$1")',$a);
Copy after login

楼上都是高手

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template