Forums / Cotonti / Extensions / Function sed_cutpost?

musiconly
#1 2009-04-30 01:48
I'm using this function for cutting down some stuff on my site, like bio previews and stuff like that.

And I'm using it as parse_bbcodes=false, but this function only removes [bbcode][/bbcode] while still outputting the data that was between that two codes.

For example, using sed_cutpost function, parse_bbcodes=false:

[img]someimage.jpg[/img]Lorem ipsum at something more of this and more and more

after it passes the function, it will be
someimage.jpgLorem ipsum at something more of this and more and more

Is there any way to remove whole bbcodes, along with text that is using them.

So I don't get
someimage.jpgLorem ipsum at something more of this and more and more
but
Lorem ipsum at something more of this and more and more

// Cutpost
function sed_cutpost($text, $max_chars, $parse_bbcodes = true)
{
    $text = $max_chars == 0 ? $text : sed_cutstring(strip_tags($text), $max_chars);
    // Fix partial cuttoff
    $text = preg_replace('#\[[^\]]*?$#', '...', $text);
    // Parse the BB-codes or skip them
    if($parse_bbcodes)
    {
        // Parse it
        $text = sed_parse($text);
    }
    else $text = preg_replace('#\[[^\]]+?\]#', '', $text);
    return $text;
}
TwistedGA
#2 2009-04-30 06:35
I'd say the easiest option would be to strip any the text between all [bbcode][/bbcode] in the string and then strip the tags from it.
[color=#CC0000]Lazymod[/color] [color=#000000]Studios[/color]
Trustmaster
#3 2009-04-30 12:18
Dirty trick:
else
{
    $text = preg_replace('#\[[^\]]+?\](.*?)\[/[^\]]+?\]#', '', $text);
    $text = preg_replace('#\[[^\]]+?\]#', '', $text);
}
May the Source be with you!
musiconly
#4 2009-04-30 16:14
# Trustmaster : Dirty trick:
else
{
    $text = preg_replace('#\[[^\]]+?\](.*?)\[/[^\]]+?\]#', '', $text);
    $text = preg_replace('#\[[^\]]+?\]#', '', $text);
}

Perfect! Thanks Trustmaster! :-)