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);
精彩评论