How do I prevent `<br>` from parsing inside my `[code]` tags?

馋奶兔 提交于 2019-12-11 11:15:59

问题


I am having some trouble (again :P) with my BB-code system. I finally got [code] tags working using Syntax Highlighter. Now there is one problem, that when "enter" is pressed inside the script (AKA next line), the bb-code causes that enter to be replaced with <br> which means the script does not correctly render the code using Syntax Highlighter.

Example picture:

How do I create an exception in my code, that ignores the <br> when it is inside [code] lines?

My current bbcode.php (there are more things in those arrays, but they are not relevant):

function bbcode($input) {
  $find = array( 
    "@\n@", 
    "/\[code\=(.+?)\](.+?)\[\/code\]/is"
  );
  $replace = array( 
    "<br />",
    "<pre class='brush: $1;'>$2</pre>"
  );
  $input = htmlspecialchars($input);
  $input= preg_replace($find, $replace, $input);
  return $input;
}

To sum it up: How do I prevent <br> from parsing inside my [code] tags?

Thanks ahead!

来源:https://stackoverflow.com/questions/23583075/how-do-i-prevent-br-from-parsing-inside-my-code-tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!