News:

Please note these forums are mostly a testing ground for my SMF work and I don't really use them otherwise.

Main Menu

Paste-1255477513:v:use_geshi-1:v:type-php

Started by Guest, Oct 13, 2009, 11:45 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Guest

// Highlight any code...
function highlight_php_code($code)
{
   global $context;

   // Remove special characters.
   $code = un_htmlspecialchars(strtr($code, array('
', "\t", '['), array("\n", 'SMF_TAB();', '['), $code));

   // It's easier in 4.2.x+.
   if (version_compare(PHP_VERSION, '4.2.0') == -1)
   {
      ob_start();
      highlight_string($code);
      $buffer = str_replace(array("\n", "\r"), '', ob_get_contents());
      ob_end_clean();
   }
   else
      $buffer = str_replace(array("\n", "\r"), '', highlight_string($code, true));

   // Yes, I know this is kludging it, but this is the best way to preserve tabs from PHP :P.
   $buffer = preg_replace('~SMF_TAB(?:</(?:font|span)><(?:font color|span style)="[^"]*?">)?\\(\\);~', '<pre style="display: inline;">' . "\t" . '', $buffer);

   return str_replace(array('\'', '<code>', '</code>'), array('&#039;', '', ''), $buffer);
}

adfadsfadsf

// Highlight any code...
function highlight_php_code($code)
{
   global $context;

   // Remove special characters.
   $code = un_htmlspecialchars(str_replace(array('
', "\t", '&#91;'), array("\n", 'SMF_TAB();', '['), $code));

   // It's easier in 4.2.x+.
   if (version_compare(PHP_VERSION, '4.2.0') == -1)
   {
      ob_start();
      highlight_string($code);
      $buffer = str_replace(array("\n", "\r"), '', ob_get_contents());
      ob_end_clean();
   }
   else
      $buffer = str_replace(array("\n", "\r"), '', highlight_string($code, true));

   // Yes, I know this is kludging it, but this is the best way to preserve tabs from PHP :P.
   $buffer = preg_replace('~SMF_TAB(?:</(?:font|span)><(?:font color|span style)="[^"]*?">)?\\(\\);~', '<pre style="display: inline;">' . "\t" . '', $buffer);

   return str_replace(array('\'', '<code>', '</code>'), array('&#039;', '', ''), $buffer);
}