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.

Member Avatar for diafol

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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.