$srt=HDD(2GB*2)qty3##HDD(4GB*2)qty4##HDD(2GB*2)qty5
在上面的例子中,我需要用空值
替换qty +下一个数值答案 0 :(得分:0)
这种情况最简单的方法是使用preg_replace
函数:
$srt= "HDD(2GB*2)qty3##HDD(4GB*2)qty4##HDD(2GB*2)qty5";
$srt = preg_replace("/qty\d+?/", "", $srt);
print_r($srt); // "HDD(2GB*2)##HDD(4GB*2)##HDD(2GB*2)"
对于其他条件:'将qty3 ##替换为“,”'
...
$srt = preg_replace("/qty\d+?##/", " ,", $srt);
答案 1 :(得分:0)
我会使用正则表达式替换:
$srt="HDD(2GB*2)qty3##HDD(4GB*2)qty4##HDD(2GB*2)qty5";
preg_replace("/qty\\d/", "", $srt);
答案 2 :(得分:0)
对this+immediate next character in php
<?php
$string = 'HDD(2GB*2)qty3##HDD(4GB*2)qty4##HDD(2GB*2)qty5';
$pattern = '/qty\w/';
$replacement = '';
echo preg_replace($pattern, $replacement, $string);
?>
输出是:
HDD(2GB*2)##HDD(4GB*2)##HDD(2GB*2)