php - How to regex replace tag followed by newline? -


i want use preg_replace_callback replace instances of custom tag markup. instance, i'm using code replace instances of "[tube]...[/tube]":

preg_replace_callback('/\[tube\](.*)\[\/tube\]/', array('myclass', 'mycallback'), $data); 

the problem not match this:

[tube] http://www.somesite.com [/tube] 

how can this?

note: yes familiar pecl bbcode extension, pear library. want without them.

you have use pattern modifiers.

s (pcre_dotall) if modifier set, dot metacharacter in pattern matches characters, including newlines. without it, newlines excluded. modifier equivalent perl's /s modifier. negative class such [^a] matches newline character, independent of setting of modifier.

preg_replace_callback('/\[tube\](.*)\[\/tube\]/smu', array('myclass', 'mycallback'), $data); 

http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php


Comments