开发者

If statement inside preg_replace?

开发者 https://www.devze.com 2023-03-19 02:55 出处:网络
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 \"

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".

0

精彩评论

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