Jump to content

PHP HTML help


palcrypt

Recommended Posts

I'm editing the pn_bbcode module in postnuke, but I'm pretty new to PHP. I've got a small problem that's driving me nuts. I have a string variable set to contain a series of html tags. The first part of this is a table tag. For some reason when the function is called the "<" and ">" in the first tag in the string only is replaced with it's
[code]&lt;[/code] and [code]&gt;[/code] respectively. I can't figure out why this is.

Here's the entire function. I used another function in the script as a starting point, but it seems, to me anyway, that I edited everything properly.
[code]/**
* Paul Romer - May 19, 2006
* Perfroms [hide][/hide] bbencoding on the given string, and returns the results.
* code samples ussed from the pn_bbcode_encode_quote function by Nathing Codding
*/
function pn_bbcode_encode_hide($message)
{
    // If there aren't any "[hide=" or "[hide]" strings in the message, we don't need to process
    if (!strpos(strtolower($message), "[hide=") && !strpos(strtolower($message), "[hide]")) {
        return $message;
    }
    
    add_stylesheet_header();
    
    $stack = Array();
    $curr_pos = 1;
    while ($curr_pos && ($curr_pos < strlen($message))) {
        $curr_pos = strpos($message, "[", $curr_pos);

        // If not found, $curr_pos will be 0, and the loop will end.
        if ($curr_pos) {
            // We found a [. It starts at $curr_pos.
            // check if it's a starting or ending hide tag.
            $possible_start = substr($message, $curr_pos, 5);
            $possible_end_pos = strpos($message, "]", $curr_pos);
            $possible_end = substr($message, $curr_pos, $possible_end_pos - $curr_pos + 1);
            if (strcasecmp("[hide", $possible_start) == 0)
            {
                // We have a starting hide tag.
                // Push its position on to the stack, and then keep going to the right.
                array_push($stack, $curr_pos);
                ++$curr_pos;
            } else if (strcasecmp("[/hide]", $possible_end) == 0) {
                // We have an ending quote tag.
                // Check if we've already found a matching starting tag.
                if (sizeof($stack) > 0) {
                    // There exists a starting tag.
                    // We need to do 2 replacements now.
                    $start_index = array_pop($stack);

                    // everything before the [hide=xxx] tag.
                    $before_start_tag = substr($message, 0, $start_index);

                    // find the end of the start tag
                    $start_tag_end = strpos($message, "]", $start_index);
                    $start_tag_len = $start_tag_end - $start_index + 1;
                    if($start_tag_len > 6) {
                        $title = substr($message, $start_index + 6, $start_tag_len - 7);
                    } else {
                        $title = "";
                    }

                    // everything after the [hide=xxx] tag, but before the [/hide] tag.
                    $between_tags = substr($message, $start_index + $start_tag_len, $curr_pos - ($start_index + $start_tag_len));
                    // everything after the [/hide] tag.
                    $after_end_tag = substr($message, $curr_pos + 7);
                    $hidetext = '<table width=500 cellpadding=3 cellspacing=0 class="hidetable"><tr><td><div class="hideheader">' . $title . '</div><p><div class="hidetextvis">' . $between_tags . '</div></td></tr></table>';
                    $message = $before_start_tag . $hidetext . $after_end_tag;

                    // Now.. we've screwed up the indices by changing the length of the string.
                    // So, if there's anything in the stack, we want to resume searching just after it.
                    // otherwise, we go back to the start.
                    if (sizeof($stack) > 0) {
                        $curr_pos = array_pop($stack);
                        array_push($stack, $curr_pos);
                        ++$curr_pos;
                    } else {
                        $curr_pos = 1;
                    }
                } else {
                    // No matching start tag found. Increment pos, keep going.
                    ++$curr_pos;
                }
            } else {
                // No starting tag or ending tag.. Increment pos, keep looping.,
                ++$curr_pos;
            }
        }
    } // while

    return $message;
}[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.