Cleaning up <pre> tag content
I'm blogging for different technologies, but very often I need to add some code in my articles. This little PHP function helps me to keep the text in my
tags clean for prettify. It simply removes the
's and keeps the html tags.
function fixPreTags($str) { $parts = explode('
', $str); $newStr = ''; if(count($parts) > 1) { foreach ($parts as $p) { $parts2 = explode('', $p); if(count($parts2) > 1) { $code = str_replace('
', '', $parts2[0]); $code = str_replace('
', '', $code); $code = str_replace('
', '', $code); $code = str_replace('<', '<', $code); $newStr .= '
'.$code.''; $newStr .= $parts2[1]; } else { $newStr .= $p; } } } else { $newStr = $str; } return $newStr; }