Viewing Paste 392

Formated Paste

  1. // Highlight any code...
  2. function highlight_php_code($code)
  3. {
  4. global $context;
  5.  
  6. // Remove special characters.
  7. $code = un_htmlspecialchars(str_replace(array('<br />', "\t", '&#91;'), array("\n", 'SMF_TAB();', '['), $code));
  8.  
  9. // It's easier in 4.2.x+.
  10. if (version_compare(PHP_VERSION, '4.2.0') == -1)
  11. {
  12. $buffer = str_replace(array("\n", "\r"), '', ob_get_contents());
  13. }
  14. else
  15. $buffer = str_replace(array("\n", "\r"), '', highlight_string($code, true));
  16.  
  17. // Yes, I know this is kludging it, but this is the best way to preserve tabs from PHP :P.
  18. $buffer = preg_replace('~SMF_TAB(?:</(?:font|span)><(?:font color|span style)="[^"]*?">)?\\(\\);~', '<pre style="display: inline;">' . "\t" . '</pre>', $buffer);
  19.  
  20. return str_replace(array('\'', '<code>', '</code>'), array('&#039;', '', ''), $buffer);
  21. }
Name:
Email:
Code/text to paste:
  • Enable code highlighting
  • Code Language:
  • A duck, cat and a goose walk into a bar. How many animals walked into a bar?:
Highslide for Wordpress Plugin