I want to replace content from a string which is contained within {content}. It an be开发者_JAVA技巧 multilines etc. The preg_replace function should remove the whole { com no mat ment }
Try this:
$result = preg_replace('/\{[^}]*\}/s', 'replacement content', $subject);
Update
$str = preg_replace('/(?<=\{).+?(?=\})/s', '', $str);
See it.
preg_match_all('/{*([^}]+*)}/s'), $content, $matches)
How is this?
preg_match_all('/\{([^}]+\)}/s'), $content, $matches)
You need the s
modifier to make the expression work with newlines. The $matches
array will contain all the matching segments which you can then replace.
精彩评论