php bbcode实现,PHP BBCode Parser

I have a tiny bbcode parser which works very well, except pre and code tags. I need to make pre and code tags ignored by the whole parser function. How would I achive this ? If any one have an idea please let me know.

What I'm trying to do is when I use

 or  tags it will ignore the bbcode used inside, but parse it everywhere else on the page.  I think it can be achived with regex and preg_match or preg_replace some how.function parse($text) {

$search = array(

'/**(.*?)**/is', // bold

'///(.*?)///is', // italic

'/__(.*?)__/is', // underline

); #search

$replace = array(

'$1',

'$1',

'$1',

); #replace

return preg_replace($search, $replace, $text);

} #parse

** Bold Text **

// Italic Text //

__ Uderline Text __

** Bold Text **

// Italic Text //

__ Uderline Text __

Any help will be apreceated. Thank you.

First of all, that's not BBCode. BBCode uses [ and ] as delimiters to mimic common HTML markup tags. What you have there, is something similar to Markdown or reStructuredText.

Secondly, you replacement algorithm is extremely simple and likely to give you much trouble in the future. If you are not merely doing this to learn how to code in PHP, I'd suggest you use existing parsers that already do what you want to do, like PHP Markdown, PHP reStrucuredText or PHP BBCode Parser.

Now, as for your actual question: This will not be easy, but you can start with altering your regexes so they only apply if they are not inside

 tags like this: (untested)'/(?).*?**(.*?)**.*?(?!
)/is', // bold

链接地址: http://www.djcxy.com/p/29872.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值