开发者

preg_replace delimiters with HTML tags

I would like to use some kind of BB code for a php application: If you are writing text between two "slashdots" (example: To /.be/. or /.not/. to be!) it will appear italic. I'm currently using the following pattern:

preg_replace('/\/\.(.*)\/\./', '<i>$1</i>', $text)

but it would return To <i>be/. or /.not</i> to be! for that example instead of To <i>be</i> or <i>not</i> to be!...

I also tried with negative look-ahead assertion, but it throws开发者_如何学Go errors.


Use non-greedy match (question mark):

preg_replace('/\/\.(.*?)\/\./', '<i>$1</i>', $text);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜