Jay Wit Jay Wit - 1 month ago 5x
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
it should remove the whole string, so:

This is , welcome.

How can I do this?

Thanks in advance!


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

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