eevan79 Posted August 2, 2010 Share Posted August 2, 2010 I dont know how to solve this. I installed syntax highlight script for my forum script. And its working, but when I write some code I get following: function highlight_search($search_words,$string,$bgcolors='yellow') <br> { <br> if (is_array($bgcolors)) { <br> $no_colors=count($bgcolors); <br> } else { <br> $temp=$bgcolors; <br> unset($bgcolors); <br> $bgcolors[0]=$temp; <br> $no_colors=1; <br> } <br> $word_no=0; This is example code and you can see <br> at every line. Here is used bbcode: function BBCode ($text) { $search = array( '/\[php\](.*?)\[\/php\]/is'}; and replace: $replace = array( '<pre class="brush: php;">$1</pre>'); How to remove this <br> at every line? Here is screenshot: Quote Link to comment Share on other sites More sharing options...
eevan79 Posted August 2, 2010 Author Share Posted August 2, 2010 Basically I just need to remove all <br> between [ php] and [ / php ] tags.? Quote Link to comment Share on other sites More sharing options...
eevan79 Posted August 2, 2010 Author Share Posted August 2, 2010 I solve it: $text = preg_replace('/<pre class="brush: php;">(.+?)<\/pre>/is', preg_replace('<\/br>', '$1', '<pre class="brush: php;">$1</pre>'), $text); Quote Link to comment Share on other sites More sharing options...
eevan79 Posted August 2, 2010 Author Share Posted August 2, 2010 cant edit post $text = preg_replace ('/<pre class="brush: php;">(.+?)<\/pre>/is', preg_replace('<\/br>', '$1', '<pre class="brush: php;">$1</pre>'), $text); script above not working...something is wrong. Quote Link to comment Share on other sites More sharing options...
newbtophp Posted August 3, 2010 Share Posted August 3, 2010 <?php function callback($match) { return '<pre class="brush: php;">'.preg_replace("~<br.+?>~i", "\n" $match[1]).'</pre>'; } $str = preg_replace_callback('/\[php\](.*?)\[\/php\]/is', 'callback', $str); echo $str; ?> Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted August 3, 2010 Share Posted August 3, 2010 What syntax highlighter are you using? I've used GeSHi, and had no problems with that. Quote Link to comment Share on other sites More sharing options...
eevan79 Posted August 3, 2010 Author Share Posted August 3, 2010 I get this for function callback: Parse error: syntax error, unexpected T_VARIABLE What syntax highlighter are you using? I've used GeSHi, and had no problems with that. I am using this: http://alexgorbatchev.com/SyntaxHighlighter/download/ Quote Link to comment Share on other sites More sharing options...
eevan79 Posted August 3, 2010 Author Share Posted August 3, 2010 Again cant edit post . Sry. I found why I get this <br> . Before text is inserted into database I use some BBCode parser and this code: $text = str_replace("\n", "<br>", $text); Without this code I dont have new lines, but also it disaplay <br>'s in [php ] tags. I think I need to remove all <br>'s here (when parsing bbcodes): <pre class="brush: php;">$1</pre> [/code] Quote Link to comment Share on other sites More sharing options...
eevan79 Posted August 3, 2010 Author Share Posted August 3, 2010 That was problem with highlight script. And I found solution to stripBrs. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.