I'm using this code currently, to convert a BBCode Quote tag to HTML. As you probably know, a quote sourc开发者_JS百科e isn't necessary to make a quote on most forums. And I'd like to print just "Quote" when there's no quote source specified.
$string = preg_replace("/\[quote(|=(.*?))\]/is","<fieldset style=\"border:1px dashed #999999;\"><legend>$2</legend>",$string);
It seems like I can't use an if statement with the $2 reference. So what's my alternative? (Or am I just doing something wrong... ?)
Please have a look preg_replace_callback. You can pass a callback that gets called for every match. In this callback you will be able to modify the matches and set the default to "Quote".
精彩评论