Jay Wit Jay Wit - 3 months ago 7
PHP Question

How to remove word when it contains x?

I'm trying to do a replace on a piece of string. For example:

This is !c-myName!, welcome.


What I want is that if the string contains
!c-
it should remove the whole string, so:

This is , welcome.


How can I do this?

Thanks in advance!

[Edit:]

When the string contains
!c- blaa!
, it should remove everything until the next
!
, sorry for not clearing that :)

Answer
$string = "This is !c-myName!, welcome.";
$pattern = '/!c-[^!]+!/';
$result = preg_replace($pattern, '', $string);
echo $result;

fiddle