Heim >Backend-Entwicklung >PHP-Tutorial >,PHP替换指定位置的字符串

,PHP替换指定位置的字符串

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 12:14:051569Durchsuche

在线等,急。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+ 通过

$a = '36,0.00,0.00,100<br><font color='#FF8000'>------解决思路----------------------</font><br>37,0.00,0.00,100<br><font color='#FF8000'>------解决思路----------------------</font><br>38,0.00,0.00,100<br><font color='#FF8000'>------解决思路----------------------</font><br>39,0.00,0.00,100';<br />$b='38';<br />$c='85';<br /><br />echo preg_replace_callback("/(^<br><font color='#FF8000'>------解决思路----------------------</font><br>\<br><font color='#FF8000'>------解决思路----------------------</font><br>$b,0.00,0.00,)100/", function($m) use ($c){ return $m[1].$c;}, $a);
36,0.00,0.00,100
------解决思路----------------------
37,0.00,0.00,100
------解决思路----------------------
38,0.00,0.00,85
------解决思路----------------------
39,0.00,0.00,100

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:汉语转换内码Nächster Artikel:PHP的PSR系列轨范都有啥内容