Shaonline
Shaonline

Reputation: 1637

How to replace string with tags used

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

Answers (2)

JMozac
JMozac

Reputation: 61

for Case Insensitive, use

str_ireplace()

instead of `

str_replace()

`

Upvotes: 1

Nir Alfasi
Nir Alfasi

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

Related Questions