,PHP替换指定位置的字符串
程序员文章站
2022-05-31 17:25:21
...
在线等,急。PHP替换指定位置的字符串
$a = '36,0.00,0.00,100|37,0.00,0.00,100|38,0.00,0.00,100|39,0.00,0.00,100';
$b='38';
$c='85';
用PHP怎么做一替换。。。
就是说 当$a中 包含$b中的字数后。 把38,0.00,0.00,100 中的100替换成$c中的数字。
如果$b=‘37’
那么就把37,0.00,0.00,100 中的100替换成$c中的数字。
谢谢各位了
------解决思路----------------------
php5.3+ 通过
------解决思路----------------------
37,0.00,0.00,100
------解决思路----------------------
38,0.00,0.00,85
------解决思路----------------------
39,0.00,0.00,100
$a = '36,0.00,0.00,100|37,0.00,0.00,100|38,0.00,0.00,100|39,0.00,0.00,100';
$b='38';
$c='85';
用PHP怎么做一替换。。。
就是说 当$a中 包含$b中的字数后。 把38,0.00,0.00,100 中的100替换成$c中的数字。
如果$b=‘37’
那么就把37,0.00,0.00,100 中的100替换成$c中的数字。
谢谢各位了
------解决思路----------------------
php5.3+ 通过
$a = '36,0.00,0.00,10036,0.00,0.00,100
------解决思路----------------------
37,0.00,0.00,100
------解决思路----------------------
38,0.00,0.00,100
------解决思路----------------------
39,0.00,0.00,100';
$b='38';
$c='85';
echo preg_replace_callback("/(^
------解决思路----------------------
\
------解决思路----------------------
$b,0.00,0.00,)100/", function($m) use ($c){ return $m[1].$c;}, $a);
------解决思路----------------------
37,0.00,0.00,100
------解决思路----------------------
38,0.00,0.00,85
------解决思路----------------------
39,0.00,0.00,100
相关文章
相关视频
上一篇: PHP遍历文件夹与子目录
下一篇: iOS11 开发遇到的坑。。。