Hi,
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 :
content_handling
optional - Gives the
callback used for modification of the
content. Object Oriented Notation
supported only since 0.10.1 callback
prototype is string name(string
$content, string $argument)
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 :
$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' => '',
'content_handling' => 'remove_handler',
),
);
And declaring the remove_handler
function this way :
function remove_handler($content, $argument) {
return '';
}
Or maybe that way :
function remove_handler(& $content, $argument) {
$content = '';
}
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 both open_tag
and close_tag
; that way, the content_handling
callback will be responsible for all the work.
Something like this, so :
$tags = array(
'youtube' => array(
'type' => BBCODE_TYPE_NOARG,
'open_tag' => '',
'close_tag' => '',
'content_handling' => 'generate_youtube_tag',
),
);
The callback function would then look like this :
function generate_youtube_tag($content, $argument) {
// TODO some security checks on $content !
// Here, I've assumed that a youtube id only contains letters and numbers
// But I don't know it that's always the case
if (preg_match('/^[\d\w]+$/', $content)) {
return <<<NEW_CONTENT
<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>
NEW_CONTENT;
}
else {
return '';
}
}
It actually generates the whole <object>
tag, including both occurences of the youtube's id.
And if you call it like this :
$text = '[youtube]w0ffwDYo00Q[/youtube]';
$bbHandler = bbcode_create($tags);
$output = bbcode_parse($bbHandler, $text);
var_dump($output);
You get this output :
string '<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>' (length=246)
Which kinda looks like something that should be ok ;-)
Actually, if you just ouput it :
echo $output;
The video is loaded ; it's called Simon's Cat 'Cat Man do', btw ;-)
Hope this solves your problem better, this time :-)