开发者

preg_replace delimiters with HTML tags

开发者 https://www.devze.com 2023-02-18 17:29 出处:网络
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 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

精彩评论

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