php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #59695 Callback for handling BBCode Tags
Submitted: 2011-03-29 07:27 UTC Modified: 2011-03-29 08:41 UTC
From: harald dot lapp at gmail dot com Assigned:
Status: Closed Package: bbcode (PECL)
PHP Version: 5.3.5 OS: linux
Private report: No CVE-ID: None
 [2011-03-29 07:27 UTC] harald dot lapp at gmail dot com
Description:
------------
It would be very nice, if you could specify a callback for 
bbcode tags. This would be very useful for example for a forum 
etc. where you add a post-id as argument for the "quote" tag.

With a callback you could handle the argument and fetch 
further information of the quoted text, e.g.: author-name etc.


Reproduce code:
---------------
<?php

$string = <<<EOT
[quote=1234]
some-quoted-text
[/quote]

some more text
EOT;

$bbcode = array(
    ''  => array(
        'type' => BBCODE_TYPE_ROOT
    ),
    'quote' => array(
        'type'     => BBCODE_TYPE_OPTARG, 
        'open_tag' => function(arg) {
            // do some stuff here like DB lookups etc, to get additional information for specified argument
            return "<blockquote><a href="...">" . $author_name . "</a></blockquote><br />";
        },
        'close_tag' => '</blockquote>'
    )
);

$bbhandler = bbcode_create($bbcode);
bbcode_parse($bbh, $string);

?>

Expected result:
----------------
<blockquote><a href="...">author_name</a><br />
some-quoted-text
</blockquote>

some more text



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-29 08:41 UTC] xdecock at gmail dot com
Thank you for your bug report. This issue has been fixed
in the latest released version of the package, which you can download at
http://pecl.php.net/get/bbcode

The content And param handlers already work this way, I don't see the point. Callbacks are already implemented altough not this way...

Check this page. http://be.php.net/manual/en/function.bbcode-create.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 18:01:28 2024 UTC