コード例 #1
0
 public static function clean_code($code, $escape = TRUE, $spaces = FALSE, $tabs = FALSE, $lines = FALSE)
 {
     if (empty($code)) {
         return $code;
     }
     /* Convert <, > and & characters to entities, as these can appear as HTML tags and entities. */
     if ($escape) {
         $code = CrayonUtil::htmlspecialchars($code);
     }
     if ($spaces) {
         // Replace 2 spaces with html escaped characters
         $code = preg_replace('#[ ]{2}#msi', '&nbsp;&nbsp;', $code);
     }
     if ($tabs) {
         // Replace tabs with 4 spaces
         $code = preg_replace('#\\t#', str_repeat('&nbsp;', CrayonGlobalSettings::val(CrayonSettings::TAB_SIZE)), $code);
     }
     if ($lines) {
         $code = preg_replace('#(\\r\\n)|\\r|\\n#msi', "\r\n", $code);
     }
     return $code;
 }