php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #59274 Add parser callback for non BBcode strings
Submitted: 2010-06-20 09:57 UTC Modified: 2017-04-01 19:31 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: hiram_ at gmx dot net Assigned:
Status: Wont fix Package: bbcode (PECL)
PHP Version: 5.3.2 OS: Solaris
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: hiram_ at gmx dot net
New email:
PHP Version: OS:

 

 [2010-06-20 09:57 UTC] hiram_ at gmx dot net
Description:
------------
I want to replace newlines with <br /> while parsing BBcode and do some more special replacements. But since our youtube tag replacement includes some newlines, those are replaced by <br /> to. 

Is it possible to add an generic content handler?

so for example for the string "hello [b]this[/b] is [i]bold[/i]"

and the parser below

that handler would get called with "hello ", " is " and "this"

Reproduce code:
---------------
<?php
$string = "hello [b]this[/b] is [i]bold[/i]";


$BBCode = array(
''=> array( 
   'type' => BBCODE_TYPE_ROOT),
'generic'=> array( 
   'type' => BBCODE_TYPE_GENERIC,
   'content_handling'=> 'contentHandler'),
'b'=> array(
   'type' => BBCODE_TYPE_NOARG,
   'open_tag'=> '<strong>',
   'close_tag'=> '</strong>'),
'i'=> array(
   'type' => BBCODE_TYPE_NOARG,
   'child' => '!generic',
   'open_tag'=> '<em>',
   'close_tag'=> '</em>'),
);

$BBHandler = bbcode_create($BBCode);
bbcode_parse($BBHandler, $string);

function contentHandler($content)
{
 echo "'$content'\n";
}
?>

Expected result:
----------------
'hello '
'this'
' is '



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-20 11:29 UTC] xdecock at gmail dot com
it will be a default content handling?

better to add a function bbcode_set_default_handler() IMHO,

if this is ok for you, i can make a publication in a few hours.

Xavier.
 [2010-12-02 18:59 UTC] hiram_ at gmx dot net
Yes, i think that would suffice.
 [2011-06-18 11:10 UTC] hiram_ at gmx dot net
On second thought: a default handler would not be enough since given this example 
"hello [b]this is [i]bold[/i] not italic[/b]"
it would be called with 
"bold", 
"this is <em>bold</em> not italic" and 
"hello <strong>this is <em>bold</em> not italic</strong>"

instead of "hello", "this is ", "bold" and "not italic"

so my handler would only be called with leaf nodes (if you consider every text in a tag seperated by another tag as a seperate node like in xml happens)

This is usefull to have for example nl2br as a default text content handler and be able to disallow it in certain tags
 [2011-10-21 23:11 UTC] hiram_ at gmx dot net
I believe that a callback at the same point were smileys are parsed would suffice. At least if i understand the code correctly.
 [2011-11-21 23:33 UTC] hiram_ at gmx dot net
Actually smilies solved part of my problem:

a smilie defined a  "\n", "<br />\n" has the same effect as nl2br without the problem of adding <br />'s in youtube object elements.

However the other part of my problem cannot be solved without regexes. So probably a way to use regexes for smilies or a smilie handler (although in my case not for smilies, but to make links clickable)  would solve my problem.
 [2017-04-01 19:31 UTC] tpunt@php.net
-Status: Open +Status: Wont fix
 [2017-04-01 19:31 UTC] tpunt@php.net
Due to this extension not seeing any activity since 2010, this issue will not be fixed. We are therefore closing this now.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC