Home >Backend Development >PHP Tutorial >preg_replace 有关问题,求帮助

preg_replace 有关问题,求帮助

WBOY
WBOYOriginal
2016-06-13 12:21:411075browse

preg_replace 问题,求帮助

<br /><?php <br />$wupin="A类别0::::::品名1::::::品牌/厂商2::::::规格3::::::要改变的数量4::::::单位5::::::单价6::::::要改变的总价7|||||||B类别0::::::品名1::::::品牌/厂商2::::::规格3::::::要改变的数量4::::::单位5::::::单价6::::::要改变的总价7";<br /><br />$strrpos_start="A类别0::::::品名1::::::品牌/厂商2::::::规格3::::::";//查询前面部分<br />$strrpos_end="单位5::::::单价6::::::";//查询后面部分<br /><br />$k =$strrpos_start;<br />$n =10;<br />echo preg_replace("/(?<=$k )\d+/e", '0 + '.$n, $wupin);//行不通,出错<br />?><br /><br />


想把A类别中的“要改变的数量4” 里的数量再加上10
------解决思路----------------------
$wupin="A类别0::::::品名1::::::品牌/厂商2::::::规格3::::::要改变的数量4::::::单位5::::::单价6::::::要改变的总价7<br><font color='#FF8000'>------解决思路----------------------</font><br>B类别0::::::品名1::::::品牌/厂商2::::::规格3::::::要改变的数量4::::::单位5::::::单价6::::::要改变的总价7";<br /> <br />$ep = explode('<br><font color='#FF8000'>------解决思路----------------------</font><br>', $wupin);<br />if($ep[0][0] == 'A'){<br />  $ep[0] = preg_replace_callback("/(要改变的数量)(\d)/", create_function('$matches','return $matches[1].($matches[2]+10);'), $ep[0]);<br />}<br />echo join($ep);

Statement:
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