You are here

function codefilter_process_php in Code Filter 6

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

Processes chunks of escaped PHP code into HTML.

1 string reference to 'codefilter_process_php'
codefilter_filter in ./codefilter.module
Implementation of hook_filter()

File

./codefilter.module, line 26

Code

function codefilter_process_php($matches) {

  // 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('\\"', '"', $matches[1]));

  // 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">' . highlight_string("<?php\n{$text}\n?>", 1) . '</div>';

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