Tush Tush - 4 months ago 9
PHP Question

Remove substring like this+immediate next character in php

$srt=HDD(2GB*2)qty3##HDD(4GB*2)qty4##HDD(2GB*2)qty5


In above example i need to replace qty+next numeric value with null

Answer

The simplest way for such case is using preg_replace function:

$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)"

For additional condition: 'replace qty3## like all with " ,"'

...
$srt = preg_replace("/qty\d+?##/", " ,", $srt);
Comments