cocacola90 / syntaxhighlighter

Automatically exported from code.google.com/p/syntaxhighlighter
GNU General Public License v3.0
0 stars 0 forks source link

Syntax Highlighter & nl2br (php)!!! #151

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I Use Syntax Highlighter to highlight the code got from database
Next, I Use function nl2br() in PHP to turn new-line char (/n) to "<br>" tag

The Problem is:
Text outside is displayed normally, but text inside the code box
(highlighted by S.H) isn't. There are "<br>" displayed after every line of
code in the code box. >> See the screenshot:
http://img17.imageshack.us/img17/6444/mywebnl2brsh.gif

I'm using Syntax Highlighter 2.0

Please help me to fix it.

Original issue reported on code.google.com by gauluck...@gmail.com on 21 Apr 2009 at 10:10

GoogleCodeExporter commented 8 years ago
I am also having the same issue, please help!

Original comment by nerdyhe...@gmail.com on 11 May 2009 at 9:02

GoogleCodeExporter commented 8 years ago
Use this function:

function nl2brPre($input) {
    $input = preg_replace('%\n%i','<br/>',$input);
    preg_match_all('%<pre\s*[^>]*>.+?</pre>%i',$input,$a);
    for($i=0;$i<sizeof($a);$i++){
            $input = str_replace($a[$i],str_replace("<br/>","\n",$a[$i]),$input);
    }
    return $input; 
}

Original comment by ziebe...@gmail.com on 30 Aug 2009 at 12:28

GoogleCodeExporter commented 8 years ago
Very helpful, thank you!

Original comment by leonli...@gmail.com on 27 Aug 2010 at 4:44