0

Hi
I write a bbcode and I have a problem. I have this code:

function bbcode($tresc) 
{
  //...
  $tresc=str_replace("\n",'<br />',$tresc);
  $tresc=preg_replace('/\[\-\]([\w\W]+?)\n?(?=(?:(?:\[\-\])|(?:\[\/lista\])))/is','<li>\\1</li>',$tresc);
  $tresc=preg_replace("/\[lista\](.*?)\[\/lista\]/is",'<ul>\\1</ul>',$tresc);
  return $tresc;  
}

I would like to in the tag [list] [/ list] - sign <br /> - turned to back to \n
I do not know how to do it. Please help.

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by diafol
0

I modified a bit of code from the php manual (http://www.php.net/manual/fr/function.nl2br.php#100120):

$tresc = "[lista]hope\nhope\nancwjnc[/lista]";

function my_nl2br($list){
    if(preg_match_all('/\[lista\](.*?)\[\/lista\]/is', $list, $match)){
        foreach($match as $m){
            foreach($m as $guts){
            $list = str_replace('[lista]'.$guts.'[/lista]', "[lista]".str_replace("\n", "<br />", $guts)."[/lista]", $list);
            }
        }
    }
return $list;
}

echo my_nl2br($tresc);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.