久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

解析 bbcode 的最佳方式

Best way to parse bbcode(解析 bbcode 的最佳方式)
本文介紹了解析 bbcode 的最佳方式的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想為 php 網站開發 bbcode 過濾器.(我正在使用 cakephp,它將是一個 bbcode 助手)我有一些要求.

I'd like to work on a bbcode filter for a php website. (I'm using cakephp, it would be a bbcode helper) I have some requirement.

Bbcodes 可以嵌套.所以這樣的事情是有效的.

[block]  
    [block]  
    [/block]  
    [block]  
        [block]  
        [/block]  
    [/block]  
[/block]  

Bbcodes 可以有 0 個或多個參數.

例如:

[video: url="url", width="500", height="500"]Title[/video]

Bbcodes 可能有多種行為.

假設,[url]text[/url] 將被轉換為 [url:url="text"]text[/url]或者視頻 bbcode 將能夠在 youtube、dailymotion 之間進行選擇......

Let say, [url]text[/url] would be transformed to [url:url="text"]text[/url] or the video bbcode would be able to choose between youtube, dailymotion....

我認為它滿足了我的大部分需求.我已經用正則表達式做了一些事情.但我最大的問題是匹配參數.事實上,我得到了嵌套的 bbcode 和帶有 0 個參數的 bbcode.但是當我為參數添加正則表達式匹配時,它沒有正確匹配嵌套的 bbcode.

I think it cover most of my needs. I alreay done something with regex. But my biggest problem was to match parameters. In fact, I got nested bbcode to work and bbcode with 0 parameters. But when I added a regex match for parameters it didn't match nested bbcode correctly.

"[($tag)(=.*)"](.*)[/1]"//這不是 .* 而是非-grey 匹配器

"[($tag)(=.*)"](.*)[/1]" // It wasn't .* but the non-gready matcher

我現在沒有完整的正則表達式,但我有類似的東西(上圖).

I don't have the complete regex with me right now, But I had something that looked like that(above).

那么有沒有一種方法可以將 bbcode 與正則表達式或其他東西有效匹配.我唯一能想到的是使用訪問者模式并以這種方式將我的文本與每個可能的標簽分開,我可以對我的文本解析有更多的控制,我可能會驗證我的文檔,如果輸入文本沒有'沒有有效的 bbcode.我可以在保存任何內容之前通知用戶有錯誤.

So is there a way to match bbcode efficiently with regex or something else. The only thing I can think of is to use the visitor pattern and to split my text with each possible tags this way, I can have a bit more of control over my text parsing and I could probably validate my document so if the input text doesn't have valid bbcode. I could Notify the user with a error before saving anything.

我會使用 sablecc 來創建我的文本解析器.http://sablecc.org/

I would use sablecc to create my text parser. http://sablecc.org/

有什么更好的主意嗎?或者任何可以導致高效靈活的 bbcode 解析器的東西?

Any better idea? or anything that could lead to a efficient flexible bbcode parser?

謝謝你,抱歉我的英語不好...

Thank you and sorry for my bad english...

推薦答案

pecl和 PEAR BBCode 解析庫.軟件已經夠難了,無需自己重新發明多年的工作.

There's both a pecl and PEAR BBCode parsing library. Software's hard enough without reinventing years of work on your own.

如果這些都不是一個選項,我會專注于將 BBCode 轉換為有效的 XML 字符串,然后使用您最喜歡的 XML 解析例程.這里的想法非常粗略,但是

If neither of those are an option, I'd concentrate on turning the BBCode into a valid XML string, and then using your favorite XML parsing routine on that. Very very rough idea here, but

  1. 通過 htmlspecialchars 運行代碼以轉義任何需要轉義的實體

  1. Run the code through htmlspecialchars to escape any entities that need escaping

將所有 [ 和 ] 字符轉換為 <和 >分別

Transform all [ and ] characters into < and > respectively

不要忘記考慮 [tagname:

Don't forget to account for the colon in cases like [tagname:

如果 BBCode 嵌套正確,您應該設置為將此字符串傳遞到 XML 解析對象(SimpleXML、DOMDocument 等)

If the BBCode was nested properly, you should be all set to pass this string into an XML parsing object (SimpleXML, DOMDocument, etc.)

這篇關于解析 bbcode 的最佳方式的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動作視圖助手 - 解決方法?)
Is this a good way to match URI to class/method in PHP for MVC(這是將 URI 與 PHP 中用于 MVC 的類/方法匹配的好方法嗎)
Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(視圖),以便我的應用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發技術
Having a single entry point to a website. Bad? Good? Non-issue?(有一個網站的單一入口點.壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 中文字幕日韩一区 | 99在线免费视频 | 久久欧美高清二区三区 | 国产精品一区二区无线 | 日韩在线观看网站 | 国产精品久久久亚洲 | 久久精品中文 | 精品久久影院 | 国产精品一区二区三区久久 | 精品国产一区二区在线 | 亚洲精品一区中文字幕乱码 | 91一区 | 日韩在线观看中文字幕 | 日韩a在线| 国产中文字幕在线观看 | 久久丁香 | 在线一区视频 | 91精品国产乱码久久蜜臀 | 久久综合一区 | 天堂一区| 欧美极品在线 | 高清久久久 | 精品国产伦一区二区三区观看方式 | 一级免费看片 | 日日骚av| 国产黄色小视频在线观看 | 欧美日韩91| 黄色大片视频 | 久久久天天| 日韩av在线不卡 | 中文字幕日韩欧美 | 久久国产精品亚洲 | 久久久网 | 四虎影院在线免费观看 | 国产精品美女久久久久aⅴ国产馆 | 国产丝袜人妖cd露出 | 精品99久久久久久 | 精品国产三级 | 亚洲综合婷婷 | 国产精品美女久久久久久免费 | 国产7777|