Ejemplo n.º 1
0
 function php_strip_whitespace($file)
 {
     if (!@is_readable($file)) {
         return '';
     }
     $contents = join('', @file($file));
     $out = '';
     $state = 0;
     for ($i = 0; $i < strlen($contents); $i++) {
         if (!$state && is_whitespace($contents[$i])) {
             continue;
         }
         if (!$state && ($c_close = is_commentopen($contents, $i))) {
             $c_open_len = $contents[$i] == '/' ? 2 : 1;
             $i = strpos($contents, $c_close, $i + $c_open_len) + strlen($c_close) - 1;
             continue;
         }
         $out .= $contents[$i];
         if (is_quote($contents[$i])) {
             if ($state == $contents[$i] && !is_escaped($contents, $i)) {
                 $state = 0;
                 continue;
             }
             if (!$state) {
                 $state = $contents[$i];
                 continue;
             }
         }
     }
     return $out;
 }
Ejemplo n.º 2
0
 /**
  * Determines if a character at a given index is escaped or not
  *  \param index the index of the character. If null, the current $this->index
  * is used
  *  \return true or false
  */
 private function CharIsEscaped($index = null)
 {
     $index = $index !== null ? $index : $this->index;
     if (isset($this->escape_cache[$index])) {
         return $this->escape_cache[$index];
     }
     $e = is_escaped($this->input_src, $index, $this->grammar->escape_chars);
     $this->escape_cache[$index] = $e;
     return $e;
 }