引用论坛中的用户
我正在一个网站的评论部分工作,用户可以在其中引用其他用户所说的内容。这是论坛上的基本“引用”按钮。
为此使用 BBcode。但不确定如何实现结果。
这个功能通常是如何实现的呢?
我可以拥有
[quote=username] some sentence [/quote]
理想情况下可以转换为的
<blockquote>username said:
some sentence
</blockquote>
代码到目前为止,我有一个可以转换的代码
"[quote=username] ... [/quote]"
into
<blockquote> ... </blockquote>
,但我丢失了用户名,
这是我正在使用的代码
// output user comment
echo parse_quote( $row['user_comment'] );
// and this is the function to parse the quote
function parse_quote($str) {
$str = preg_replace("/\[quote=[\w\s\-\W][^\]]{1,}\]/", "<blockquote>:", $str);
$str = preg_replace("/\[\/quote\]/", "</blockquote>", $str);
return $str;
}
所以简而言之,论坛引用通常是如何完成的......这是正确的吗方式?如果是这样,我怎样才能转换
[quote=username] some sentence [/quote]
成
<blockquote>username said:
some sentence
</blockquote>
I'm working on the comments section for a site, where users can quote something another user said. This is your basic "quote" button on a forum.
Using BBcode for this. But not sure how to accomplish the result.
How is this feature usually done?
i can have
[quote=username] some sentence [/quote]
which would ideally be converted to
<blockquote>username said:
some sentence
</blockquote>
As of now, i have a code that converts
"[quote=username] ... [/quote]"
into
<blockquote> ... </blockquote>
but i lose the username
this is the code i'm using
// output user comment
echo parse_quote( $row['user_comment'] );
// and this is the function to parse the quote
function parse_quote($str) {
$str = preg_replace("/\[quote=[\w\s\-\W][^\]]{1,}\]/", "<blockquote>:", $str);
$str = preg_replace("/\[\/quote\]/", "</blockquote>", $str);
return $str;
}
So in a nutshell, how is forums quoting usually done...is it the right way? If so, how can I convert
[quote=username] some sentence [/quote]
into
<blockquote>username said:
some sentence
</blockquote>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试将其更改为以下内容:
如果您希望允许人们在不指定用户名的情况下引用,例如[quote]一些文本[/quote],则需要进行更多修改。
Try changing it to something like:
A little more modification will be required if you want to allow people to quote without specifying a username, like [quote]some text[/quote].
好吧,我建议的一件事是,您希望避免多次传递文件,PHP 提供了一种相当方便的方法,使用
preg_replace_callback()
:Well, one thing I'll suggest is that you want to avoid multiple passes through your file and PHP provides a fairly convenient way of doing that using
preg_replace_callback()
:不是,论坛一般采用以下格式:
No, Forum generally uses the following format: