开发者

Preg_replace in php

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜