You are here

function codefilter_prism_process_php in Code Filter 7

Processes chunks of escaped PHP code into HTML.

Parameters

string $text: The text to process.

Return value

string HTMl encoded, highlighted PHP code.

1 call to codefilter_prism_process_php()
_codefilter_prism_process_php_callback in modules/codefilter_prism/codefilter_prism.module
Callback to replace content of the <?php ?> elements.

File

modules/codefilter_prism/codefilter_prism.module, line 69
Text filter for highlighting PHP source code.

Code

function codefilter_prism_process_php($text) {

  // Undo linebreak escaping.
  $text = str_replace('&#10;', "\n", $text);

  // Inline or block level piece?
  $multiline = strpos($text, "\n") !== FALSE;

  // Trim first leading line break.
  $text = preg_replace('@^[ \\t]*[\\n]@', '', $text);
  $text = codefilter_fix_spaces($text);

  // Highlight as PHP.
  $text = '<code class="language-php">' . $text . '</code>';
  $text = $multiline ? '<pre class="codeblock">' . $text . '</pre>' : $text;
  return $text;
}