Codeigniter BBCODE 还是即时功能?

发布于 2024-11-24 06:33:46 字数 172 浏览 1 评论 0原文

我一直在寻找某种方法来使用 bbcode 对链接进行编码,或者手动将指定消息中的 url 转换为链接。 BBCodes 对我来说有点过时了。尽管如此,仍然大量用于诸如笑脸等之类的事情。

我希望可能混合使用这两种功能。

可以这么说,任何人都可以就他们使用或最近使用过的用于美化消息系统的东西提出建议。

I've been looking around for some way to either code up links using bbcode or manually convert a url in a specified message to a link. BBCodes to me are just getting a little old. Although, are still massively heavily used for such things as smileys etc.

I'd be looking to probably do a mixture of the two functionalities.

Can anyone advise on something they use or have used recently for prettifying a messaging system, so to speak.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痴梦一场 2024-12-01 06:33:46

至于转换链接,Codeigniter 为您提供了 url 助手

auto_link()

自动转换字符串中包含的 URL 和电子邮件地址
进入链接。示例:$string = auto_link($string);

第二个参数决定是否转换URL和电子邮件
或者只是其中之一。如果参数是,则默认行为是两者
未指定。电子邮件链接被编码为 safe_mailto(),如图所示
如上所述。

至于表情符号,也包括在内。实际上有一个 smiley helper

如果你放弃并想解析 bbcode,这里有一个由 Phil Sturgeon(Codeigniter 首席开发人员)编写的帮助程序:https://github.com/bcit-ci/CodeIgniter/wiki/BBCode-Helper

As far as converting links, Codeigniter's got you covered with the url helper:

auto_link()

Automatically turns URLs and email addresses contained in a string
into links. Example: $string = auto_link($string);

The second parameter determines whether URLs and emails are converted
or just one or the other. Default behavior is both if the parameter is
not specified. Email links are encoded as safe_mailto() as shown
above.

As for smilies, that's covered as well. There is actually a smiley helper:

If you give up and want to parse bbcode, here's a helper written by Phil Sturgeon (a lead Codeigniter developer): https://github.com/bcit-ci/CodeIgniter/wiki/BBCode-Helper

辞慾 2024-12-01 06:33:46

如果您想使用客户端进行 BBCode 解释,我已经编写了 JavaScript 中的可扩展 BBCode 解析器

它具有所有标准 BBCode 标签,但如果您的消息传递系统需要一些新标签来进行某些类型的 URL 操作,则可以轻松添加它们。例如,对于表情符号标记,您可以像这样扩展它:

"smiley": {
    openTag: function(params,content) {
        if (content === ":)") {
            return "<img src='smiley.png'/>";
        } else if (content === ":(") {
            return "<img src='frown.png'/>";
        } else {
            return "";
        }
    },
    closeTag: function(params,content) {
        return "";
    }
}

然后 BBCode 看起来像这样:

[smiley]:)[/smiley]

从中生成的 HTML 代码看起来像这样:

<img src='smiley.png'/>

这可能比您想要的更多工作,您可能会这样做不想为您的消息传递系统使用自己的自定义标签,但我想我应该提及它以防万一。

If you wanted to go with something client side for BBCode interpritation, I've written an extendible BBCode parser in JavaScript.

It has all of the standard BBCode tags, but if your messaging system needed some new tags for certain kinds of URL manipulation they could be easily added. As an example, for a smilies tag you could extend it like this:

"smiley": {
    openTag: function(params,content) {
        if (content === ":)") {
            return "<img src='smiley.png'/>";
        } else if (content === ":(") {
            return "<img src='frown.png'/>";
        } else {
            return "";
        }
    },
    closeTag: function(params,content) {
        return "";
    }
}

And then the BBCode would look something like:

[smiley]:)[/smiley]

And the HTML code it would generate from that would look like this:

<img src='smiley.png'/>

This might be more work than what you want and you may not want your own custom tags for your messaging system, but I figured I'd mention it just in case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文