i have string like example
$str = 'wap,net,web,andothers';
in my achievement i want to remove web from the string line so my expected result should be like wap,net,andothers i try with
$str = 'wap,net,web,andother';
$remove = 'web';
$str = ltrim($str, ' $remove');
var_dump($str);
but could not achieve it
big thanks in advance
Here i explode it and then filter out the keyword web
<?php
$str = 'wap,net,web,andother';
$explode = explode(',',$str);
$result = [];
foreach($explode as $value){
if($value !== 'web'){
$result[] = $value;
}
}
print_r(implode(',',$result));
?>
or simply, use php str_replace
$str = 'wap,net,web,andother';
$stringToRemove = 'web';
print_r(str_replace($stringToRemove,'',$str));
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments