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

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

WBOY
Release: 2016-06-13 12:02:58
Original
1188 people have browsed it

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

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

如果碰到这种类型的字符串,我怎么才能使用正则来替换双引号里面的逗号呢?(注:双引号里面有几个逗号不是确定的,上面的只是列子)
------解决方案--------------------
$a = 'aaa,bbb,ccc,"eee,ccc,sss,ppp",dddd,iiii,cccc';<br />echo preg_replace_callback('/".+?"/', function($r) { return str_replace(',', ' ', $r[0]);}, $a);<br />
Copy after login
aaa,bbb,ccc,"eee ccc sss ppp",dddd,iiii,cccc

------解决方案--------------------
<br />$a = 'aaa,bbb,ccc,"eee,ccc,sss,ppp",dddd,iiii,cccc';<br />
$new=preg_replace('/"(.+?)"/ies',"replace('\\1')",$a);
echo $new;
//aaa,bbb,ccc,"eeecccsssppp",dddd,iiii,cccc

function replace($str){
$return=str_replace(',','',$str);
return '"'.$return.'"';
}
Copy after login

------解决方案--------------------
$a = 'aaa,bbb,ccc,"eee,ccc,sss,ppp",dddd,iiii,cccc';<br />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