Jump to content

[SOLVED] Remove Text between tags


ChadNomad

Recommended Posts

I am getting news from a column that's in BB Code. I want snippets as "news" but I'm having some problems.

 

For example some code that comes out is

[img=http://linktoimage.com]

which I want to remove. Basically I would like to remove the tags and the text inside!

 

Help appreciated, thanks.

Link to comment
https://forums.phpfreaks.com/topic/148376-solved-remove-text-between-tags/
Share on other sites

so what your current code, as bb is on goolge everywhere.

 

example. i made a while back easy to alter.

 


<?php
/*
* Prepare the rule set 
*/
$arrayBBCode=array(
    ''=>         array('type'=>BBCODE_TYPE_ROOT,  
                       'childs'=>'!i'),
    'b'=>        array('type'=>BBCODE_TYPE_NOARG, 
                       'open_tag'=>'<b>', 
                       'close_tag'=>'</b>'),
    'u'=>        array('type'=>BBCODE_TYPE_NOARG, 
                       'open_tag'=>'<u>', 
                       'close_tag'=>'</u>', 
                       'flags'=>BBCODE_FLAGS_SMILEYS_OFF),
    'i'=>        array('type'=>BBCODE_TYPE_NOARG, 
                       'open_tag'=>'<i>', 
                       'close_tag'=>'</i>', 
                       'childs'=>'b'),
);
/* 
* Parsed Text
*/
$text=<<<EOF
[i] No parse Test [/i] 
[b] Parsed, with smiley  [/b]
[u] Parsed, with no smiley  [/u]
EOF;
/*
* Init the parser
*/
$BBHandler=bbcode_create($arrayBBCode);
/*
* Add Smiley rules to parser
*/
bbcode_add_smiley($BBHandler, "", "<img src=\"smiley.gif\" alt=\"\" />");
bbcode_add_smiley($BBHandler, "", "<img src=\"sad.gif\" alt=\"\" />");
bbcode_add_smiley($BBHandler, "", "<img src=\"happy.gif\" alt=\"\" />");
bbcode_add_smiley($BBHandler, "", "<img src=\"tong.gif\" alt=\"\" />");
bbcode_add_smiley($BBHandler, ":|", "<img src=\"special.gif\" alt=\":|\" />");
bbcode_add_smiley($BBHandler, ":6:", "<img src=\"six.gif\" alt=\":6:\" />");
/*
* Parse the text
*/
echo bbcode_parse($BBHandler,$text);
?>

 

Look at this example, if i want to remove any think i alter the code.

 

That the only way mate.

 

<?php


$var="[b]redarrow[/b]";

function AddBB($var) {
        $search = array(
                '/\[b\](.*?)\[\/b\]/is', // This line is regex bold.
                '/\[i\](.*?)\[\/i\]/is',
                '/\[u\](.*?)\[\/u\]/is',
                '/\[img\](.*?)\[\/img\]/is',
                '/\[url\](.*?)\[\/url\]/is',
                '/\[url\=(.*?)\](.*?)\[\/url\]/is'
                );

        $replace = array(
                '<strong>$1</strong>', // this makes it bold when converted.
                '<em>$1</em>',
                '<u>$1</u>',
                '<img src="$1" />',
                '<a href="$1">$1</a>',
                '<a href="$1">$2</a>'
                );

        $var = preg_replace ($search, $replace, $var);
        return $var;
}



echo ADDBB($var);

?>

i was thinking yee.

 

that maybe you can use somthink like this as a clone to do

the bb code as needed.

 

not finished theo.

 

<?php


$var="[i]redarrow[/i]";


function AddBB($var) {

                $bold=('/\[b\](.*?)\[\/b\]/is');
                $italic=('/\[i\](.*?)\[\/i\]/is');
                $underline=('/\[u\](.*?)\[\/u\]/is');
                $image=('/\[img\](.*?)\[\/img\]/is');
                $url=('/\[url\](.*?)\[\/url\]/is');
                $url2=('/\[url\=(.*?)\](.*?)\[\/url\]/is/');

        $search = array(
                
               //   un comment the bb you need.
                
                $bold,
                $italic,
                //$underline,
                //$image,
                //$url,
                //$url2
                );

                
        $replace = array(
                '<strong>$1</strong>',
                '<em>$1</em>',
                '<u>$1</u>',
                '<img src="$1" />',
                '<a href="$1">$1</a>',
                '<a href="$1">$2</a>'
                );
                
            

        $var = preg_replace ($search, $replace, $var);
        
        return $var;
}




echo ADDBB($var);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.