Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preg_replace in php

I want to replace content from a string which is contained within {content}. It an be multilines etc. The preg_replace function should remove the whole { com no mat ment }

like image 667
Speedy Wap Avatar asked May 29 '26 12:05

Speedy Wap


2 Answers

Try this:

$result = preg_replace('/\{[^}]*\}/s', 'replacement content', $subject);
like image 123
Mārtiņš Briedis Avatar answered May 31 '26 05:05

Mārtiņš Briedis


Update

$str = preg_replace('/(?<=\{).+?(?=\})/s', '', $str);

See it.

like image 39
alex Avatar answered May 31 '26 04:05

alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!