code:
$str = 'test2$test2$test3$test3$test4';
$id = 'test2';
We need to find the value of $id and remove $test2 or test2$ depending on the position test2 in the string ;
To search using:
$substr_count1 = substr_count ($str, '$test2');
$substr_count2 = substr_count ($str, 'test2$');
if ($substr_count1> 0) {
//if exist $test2 then need delete single value $test2 from row and row will be
// $str = 'test2$test3$test3$test4'
// find the value of $test2
// how to remote one value $test2
}
elseif ($substr_count2> 0) {
//if exist test2$ then need delete single value test2$ from row and row will be
// $str = 'test2$test3$test3$test4'
// find the value of test2$
// how to remote one value test2$
}
how to remove a single value?
You need to replace the first occurence of the ‘$test2’ if exists, if not, replace the first occurence of ‘test$’: