You are here

function codefilter_process_php in Code Filter 7

Same name and namespace in other branches
  1. 5 codefilter.module \codefilter_process_php()
  2. 6 codefilter.module \codefilter_process_php()

Processes chunks of escaped PHP code into HTML.

1 call to codefilter_process_php()
_codefilter_process_php_callback in ./codefilter.module
Callback to replace content of the <?php ?> elements.

File

./codefilter.module, line 10
Text filter for highlighting PHP source code.

Code

function codefilter_process_php($text) {

  // Note, pay attention to odd preg_replace-with-/e behaviour on slashes.
  // Undo possible linebreak filter conversion.
  $text = preg_replace('@</?(br|p)\\s*/?>@', '', str_replace('\\"', '"', $text));

  // Undo the escaping in the prepare step.
  $text = decode_entities($text);

  // Trim leading and trailing linebreaks.
  $text = trim($text, "\r\n");

  // Highlight as PHP.
  $text = '<div class="codeblock"><pre>' . highlight_string("<?php\n{$text}\n?>", 1) . '</pre></div>';

  // Remove newlines to avoid clashing with the linebreak filter.
  $text = str_replace("\n", '', $text);
  return codefilter_fix_spaces($text);
}