如何为 PECL bbcode 扩展创建 [youtube]-标签?
我使用 PECL bbcode 扩展 来解析 BBCode-Tags。
谁能告诉我一种替换 BBCode 标记之间的文本而不是用 HTML 标记包围文本的方法吗? 我想构建一个 [youtube]
标签:
[youtube]w0ffwDYo00Q[/youtube]
我对此标签的配置如下所示:
$tags = array(
'youtube' => array(
'type' => BBCODE_TYPE_NOARG,
'open_tag' =>
'<object width="425" height="350">
<param name="movie" value="http://www.youtube.com/v/{CONTENT}"></param>
<embed src="http://www.youtube.com/v/{CONTENT}" type="application/x-shockwave-flash" width="425" height="350"></embed>
</object>',
'close_tag' => '',
),
);
问题:需要 [youtube]
标签之间的文本 (Youtube ID)两次(对于对象和嵌入标签),所以我无法按预期使用 close_tag
。
结果:正确创建了包含 Youtube 播放器的标记,但之后打印了 Youtube-ID:
<object width="425" height="350">
<param name="movie" value="http://www.youtube.com/v/w0ffwDYo00Q"></param>
<embed src="http://www.youtube.com/v/w0ffwDYo00Q" type="application/x-shockwave-flash" width="425" height="350"></embed>
</object>w0ffwDYo00Q
有人知道如何解决此问题吗?
提前致谢!
I use the PECL bbcode extension for parsing BBCode-Tags.
Can anybody show me a way of replacing the text between the BBCode tags instead of surrounding it with HTML tags? I want to build a [youtube]
Tag:
[youtube]w0ffwDYo00Q[/youtube]
My configuration for this tag looks like this:
$tags = array(
'youtube' => array(
'type' => BBCODE_TYPE_NOARG,
'open_tag' =>
'<object width="425" height="350">
<param name="movie" value="http://www.youtube.com/v/{CONTENT}"></param>
<embed src="http://www.youtube.com/v/{CONTENT}" type="application/x-shockwave-flash" width="425" height="350"></embed>
</object>',
'close_tag' => '',
),
);
The Problem: the text between the [youtube]
tags (Youtube ID) is needed twice (for object and embed tags) so I cannot use the close_tag
as intended.
Result: the markup for inclusion of Youtube player is created correctly but after that the Youtube-ID is printed:
<object width="425" height="350">
<param name="movie" value="http://www.youtube.com/v/w0ffwDYo00Q"></param>
<embed src="http://www.youtube.com/v/w0ffwDYo00Q" type="application/x-shockwave-flash" width="425" height="350"></embed>
</object>w0ffwDYo00Q
Anybody knows how to fix this?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我现在无法测试,所以不确定它是否有效...但也许你可以尝试这个:
bbcode_create
描述了可用于配置代码的键/值。这些键之一是:
那么,如果您定义该属性,使其成为修改内容的函数的链接,该怎么办...例如,通过将其设置为空字符串来修改它?
也许是这样的:
并以这种方式声明
remove_handler
函数:或者也许那样:
如果运气好的话,这可能足以删除内容?
在对我之前的提议发表评论后进行编辑
再次嗨,
这一次,我已经尝试了我的建议,并且似乎有效;-)
首先,你可以为
open_tag
和close_tag
设置''
; 这样,content_handling
回调将负责所有工作。像这样,所以:
回调函数将如下所示:
它实际上生成整个
如果你这样称呼它:
你会得到这个输出:
这看起来应该没问题;-)
实际上,如果你只是输出它:
视频已加载; 它的名字是西蒙的猫'猫人',顺便说一句;-)
Hope this solves your problem better, this time **:-)**
I cannot test right now, so not sure it works... But maybe you can try this :
The documentation of
bbcode_create
describes the keys/values you can use to configure your tag.One of these keys is :
So, what if you define that property, so that it is a link to a function modifying the content... Modifying it by setting it to an empty string, for instance ?
Something like this, maybe :
And declaring the
remove_handler
function this way :Or maybe that way :
With a bit of luck, this might be enough to remove the content ?
EDIT after the comment about my previous proposition
Hi again,
This time, I've tried what I'm suggesting, and it seems to be working ;-)
First, you can set
''
for bothopen_tag
andclose_tag
; that way, thecontent_handling
callback will be responsible for all the work.Something like this, so :
The callback function would then look like this :
It actually generates the whole
<object>
tag, including both occurences of the youtube's id.And if you call it like this :
You get this output :
Which kinda looks like something that should be ok ;-)
Actually, if you just ouput it :
The video is loaded ; it's called Simon's Cat 'Cat Man do', btw ;-)
Hope this solves your problem better, this time **:-)**