You are here

function coder_trim_php in Coder 5

Same name and namespace in other branches
  1. 5.2 scripts/coder_format/coder_format.inc \coder_trim_php()
  2. 6.2 scripts/coder_format/coder_format.inc \coder_trim_php()
  3. 6 scripts/coder_format/coder_format.inc \coder_trim_php()
  4. 7.2 scripts/coder_format/coder_format.inc \coder_trim_php()
  5. 7 scripts/coder_format/coder_format.inc \coder_trim_php()

Trim overall code.

Strips whitespace at the beginning and end of code, removes the closing PHP tag and appends two empty lines.

1 call to coder_trim_php()
coder_format_file in scripts/coder_format/coder_format.inc
Reads, processes and writes the source code from and to a file.

File

scripts/coder_format/coder_format.inc, line 703

Code

function coder_trim_php($code) {

  // Remove surrounding whitespace
  $code = trim($code);

  // Insert CVS keyword Id
  // Search in the very first 1000 chars, insert only one instance.
  if (strpos(substr($code, 0, 1000), '$Id') === false) {
    $code = preg_replace('/<\\?php\\n/', "<?php\n// \$Id\$\n\n", $code, 1);
  }

  // Remove closing PHP tag
  if (substr($code, -2) == '?>') {
    $code = rtrim($code, '?>');
  }

  // Append two empty lines
  $code .= str_repeat(chr(10), 2);
  return $code;
}