Reputation: 1637
I want to replace the string "<Reason/>"
with empty space or just nothing.
I tried str_replace('<Reason/>','',$string)
but it won't take the tags.
I tried str_preg('<Reason/>','', $string)
but it leaves the the tags "<>"
.
I tried str_preg('/^<Reason/>/','', $string)
but its gives me exception with unknown modifier '>'
.
What can I do to remove the whole string along with tags "<Reason/>"
?
Upvotes: 1
Views: 77
Reputation: 61
for Case Insensitive, use
str_ireplace()
instead of `
str_replace()
`
Upvotes: 1
Reputation: 53525
You probably forgot to assign the result back to the original variable.
The following code works:
$string = str_replace('<Reason/>','',$string);
Full example:
$string = '<Reason/>lalala<Reason/>';
$string = str_replace('<Reason/>','',$string);
echo $string;
Output
lalala
Upvotes: 2