Skip to content

Instantly share code, notes, and snippets.

@krasimir
Last active December 12, 2015 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save krasimir/4697778 to your computer and use it in GitHub Desktop.
Save krasimir/4697778 to your computer and use it in GitHub Desktop.
The function removes <br /> tags inside <pre> tags and also make possible writing html.
private function fixPreTags($str) {
$parts = explode('<pre>', $str);
$newStr = '';
if(count($parts) > 1) {
foreach ($parts as $p) {
$parts2 = explode('</pre>', $p);
if(count($parts2) > 1) {
$code = str_replace('<br />', '', $parts2[0]);
$code = str_replace('<br/>', '', $code);
$code = str_replace('<br>', '', $code);
$code = str_replace('<', '&lt;', $code);
$newStr .= '<pre class="prettyprint linenums">'.$code.'</pre>';
$newStr .= $parts2[1];
} else {
$newStr .= $p;
}
}
} else {
$newStr = $str;
}
return $newStr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment