Menu

#80 Bbcode2html function not working with [quote][/quote]

open
nobody
None
5
2006-09-05
2006-09-05
Snardle
No

The bbcode2html function does not properly convert
[quote][/quote] into its html equivalent. Code example
below:

<?
require_once "/forums/sdk/ipbsdk_class.inc.php";
$SDK =& new IPBSDK();

$str = "This is a [b]string[/b]. Now I am
[quote]quoting something[/quote]";

echo $str."<br /><br />";

$bbstr = $SDK->bbcode2html($str);

echo $bbstr ."<br /><br />";

$htmlstr = $SDK->html2bbcode($bbstr);

echo $htmlstr . "<br /><br />";
?>

The first output is the str with the bbcode.

The second output is converted to html. Notice bold
works but quote does not.

Discussion

  • darthunrivaled

    darthunrivaled - 2006-09-26

    Logged In: YES
    user_id=1539731

    You should really have $str in one var not mult. Try to
    combine them. The reason you may be hacving problems is
    because you split it up. I also don't udnerstand why your
    setting $str then echo it follow by line breaks then you try
    to send it to another var into bbcode2html then echo it
    again with more line breaks only to do it one more time. I
    don't see why you are doing that.

    You should only do it once. You store the value in a var,
    then put in into another var that puts it into bbcode2html
    then echo that var.

    Try this:

    $str .= <<<EOF
    This is a [b]string[/b]. Now I am
    [quote]quoting something[/quote]
    <br /><br />
    EOF;

    $bbstr = $SDK->bbcode2html($str, '1');

    echo $bbstr;

    I also recommend you past $str threw this code also before
    printing it.

    if($htmlstate == 1 || $htmlstate == 2) {
    $str = str_replace('&lt;', '<', $str);
    $str = str_replace('&gt;', '>', $str);
    }

    if($htmlstate == 2) {
    $str = str_replace('\n', '<br />', $str);
    }

    Final Code:

    $str .= <<<EOF
    This is a [b]string[/b]. Now I am
    [quote]quoting something[/quote]
    <br /><br />
    EOF;

    if($htmlstate == 1 || $htmlstate == 2) {
    $str = str_replace('&lt;', '<', $str);
    $str = str_replace('&gt;', '>', $str);
    }

    if($htmlstate == 2) {
    $str = str_replace('\n', '<br />', $str);
    }

    $bbstr = $SDK->bbcode2html($str, '1');

    echo $bbstr;

     
  • Snardle

    Snardle - 2006-09-26

    Logged In: YES
    user_id=1591403

    How I did it here in the example is by no means how I was
    doing it in my code. The reason you see the line breaks
    after each output is so that you can see how the output
    remained unchanged in each subsequent function call.

    The first echo shows the original string. The second echo
    should show it as HTML and the third shows it back as
    bbcode. This was all debugging code with no actual merit
    other than to show that the function is not working with
    quotes. Its broken up into different strings as I did not
    want the line breaks to be part of the conversion html/bbcode.

    Breaking the strings into multiple parts should really have
    no difference. It is still perfectly valid PHP. As to your
    code, did you test it? When I did it is still not
    processing the [Quotes] on my end. Is it working on your end?

    You also specify htmlstate...when and where are you turning
    that flag on? I dont see those variables defined or set in
    your code. And for htmlstate 2 wouldnt it be more efficient
    to just use nl2br() here instead?

     
  • darthunrivaled

    darthunrivaled - 2006-09-26

    Logged In: YES
    user_id=1539731

    Yes BBcode does work on my end. Here is my code that I use.

    $topictitle = $topic['title'];
    $date = $topic['post_date'];
    $author = $topic['starter_name'];
    $authorid = $topic['author_id'];
    $viewtopic = $topic['post'];
    $desc = $topic['description'];
    $htmlstate = $topic['post_htmlstate'];
    $rating_total = $topic['topic_rating_total'];
    $rating_hits = $topic['topic_rating_hits'];

    if($htmlstate == 1 || $htmlstate == 2) {
    $viewtopic = str_replace('&lt;', '<', $viewtopic);
    $viewtopic = str_replace('&gt;', '>', $viewtopic);
    }

    if($htmlstate == 2) {
    $viewtopic = str_replace('\n', '<br />', $viewtopic);
    }

    // to show smileis
    $viewtopic = $GLOBALS['SDK']->bbcode2html($viewtopic, '1');

    // show date
    $date = date("M j Y, h:i A", $date);

    Also I don't think you can parse bbcode that's not use of
    the forum topic. For example your calling SDK and then
    trying to send code that's not attach to a topic id into the
    html2bbcode function. I think order for it to work it has to
    load the topic id. My example and the code above is for
    calling and parsing bbcode from a topic or post made. Not
    text outside of IPB. I could be wrong, but as SDK not
    working with quotes, it does work if you call a post that
    contains a quote.

    If your trying to do something where you want to use bbcdode
    outside a topic post, I think your going to have to use or
    make your own custom bbcode parser. As far as I know with
    the current beta release of SDK with IPB 2.1.7 bbcode shows
    up just fine. The only part of bbcode that doesn't work is
    the postsnap which shows the micro bit for and doesn't parse.

     
  • Snardle

    Snardle - 2006-09-26

    Logged In: YES
    user_id=1591403

    This is for outside topics and is part of a comment system i
    put together. My users are familiar with bbcode so I
    thought to integrate that into the comment system with the
    bbcode2html(). It works perfectly, as far as I can tell,
    with everything other than quotes. It works with standard
    formatting (colors, bold, italic, etc), links, smilies, etc.

    As far as the code in the ipbsdk_class file it seems that it
    should just accept any string and convert the bbcode to
    html. As far as I can tell it should really not require it
    to be attached to a topic/post in the forum.

     
  • darthunrivaled

    darthunrivaled - 2006-09-26

    Logged In: YES
    user_id=1539731

    Well myself I've never used it outside of a topic. Normally
    I have a forum on my site for topics that I import to the
    site. But to use SDK for a stand alone comment system I've
    never done before and wasn't sure if it could be done. But
    if you say that other bbcode works, then there could be
    something SDK is missing when calling quotes up.

     
  • Peter Walker

    Peter Walker - 2007-01-22

    Logged In: YES
    user_id=1091024
    Originator: NO

    I'm sorry, but this works for me.
    When you say it doesn't work...
    do you still see the bbcode tags?

     
  • Peter Walker

    Peter Walker - 2007-01-24

    Logged In: YES
    user_id=1091024
    Originator: NO

    This works for me...
    When you say it doesn't work, does the quote come out as appearing unformatted, or with the quote bbcode still around it?

     

Log in to post a comment.

Monday.com Logo