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: Link to comment https://forums.phpfreaks.com/topic/209570-syntax-highlighter/ 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.? Link to comment https://forums.phpfreaks.com/topic/209570-syntax-highlighter/#findComment-1094064 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); Link to comment https://forums.phpfreaks.com/topic/209570-syntax-highlighter/#findComment-1094371 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. Link to comment https://forums.phpfreaks.com/topic/209570-syntax-highlighter/#findComment-1094375 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; ?> Link to comment https://forums.phpfreaks.com/topic/209570-syntax-highlighter/#findComment-1094430 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. Link to comment https://forums.phpfreaks.com/topic/209570-syntax-highlighter/#findComment-1094450 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/ Link to comment https://forums.phpfreaks.com/topic/209570-syntax-highlighter/#findComment-1094472 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] Link to comment https://forums.phpfreaks.com/topic/209570-syntax-highlighter/#findComment-1094473 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. Link to comment https://forums.phpfreaks.com/topic/209570-syntax-highlighter/#findComment-1094838 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.