Example #1
0
function print_r_reverse($in)
{
    $lines = explode("\n", trim($in));
    if (trim($lines[0]) != 'Array') {
        // bottomed out to something that isn't an array
        return trim($in);
    } else {
        // this is an array, lets parse it
        if (preg_match("/(\\s{5,})\\(/", $lines[1], $match)) {
            // this is a tested array/recursive call to this function
            // take a set of spaces off the beginning
            $spaces = $match[1];
            $spaces_length = strlen($spaces);
            $lines_total = count($lines);
            for ($i = 0; $i < $lines_total; $i++) {
                if (substr($lines[$i], 0, $spaces_length) == $spaces) {
                    $lines[$i] = substr($lines[$i], $spaces_length);
                }
            }
        }
        array_shift($lines);
        // Array
        array_shift($lines);
        // (
        array_pop($lines);
        // )
        $in = implode("\n", $lines);
        // make sure we only match stuff with 4 preceding spaces (stuff for this array and not a nested one)
        preg_match_all("/^\\s{4}\\[(.+?)\\] \\=\\> /m", $in, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
        $pos = array();
        $previous_key = '';
        $in_length = strlen($in);
        // store the following in $pos:
        // array with key = key of the parsed array's item
        // value = array(start position in $in, $end position in $in)
        foreach ($matches as $match) {
            $key = $match[1][0];
            $start = $match[0][1] + strlen($match[0][0]);
            $pos[$key] = array($start, $in_length);
            if ($previous_key != '') {
                $pos[$previous_key][1] = $match[0][1] - 1;
            }
            $previous_key = $key;
        }
        $ret = array();
        foreach ($pos as $key => $where) {
            // recursively see if the parsed out value is an array too
            $ret[$key] = print_r_reverse(substr($in, $where[0], $where[1] - $where[0]));
        }
        return $ret;
    }
}
Example #2
0
function printDump($var, $title = '')
{
    $printBigAssoc = function ($assoc, $t = 1) use(&$printBigAssoc) {
        $is_object = null;
        if (is_array($assoc) || ($is_object = is_object($assoc))) {
            $cassoc = $is_object ? get_class($assoc) : count($assoc);
            $mt = 20;
            $display = "display: " . ($t == 1 ? 'block' : 'none') . ';';
            $script = !$is_object && $cassoc > 0 ? "> <div style=\"position: absolute; top: 1px; left: -15px; width: 10px; height: 10px; border: 1px solid #000; background: #fff; cursor: pointer; line-height: 8px; text-align: center; \" onclick=\"javascript: var list=this.parentNode.parentNode.getElementsByClassName('list')[0]; var is_hidden = list.style.display == 'none'; list.style.display= is_hidden ? 'block' : 'none'; this.innerHTML = is_hidden ? '-' : '+'; \">+</div" : '';
            if ($is_object) {
                $assoc = print_r_reverse(print_r($assoc, true));
                $title = 'Object';
            }
            $is_associative = is_associative($assoc);
            if (!$is_object) {
                $title = $is_associative ? 'Associative' : 'Array';
            }
            $contenido = "<span{$script}>{$title} ({$cassoc})</span><div class=\"list\" style=\"{$display}\">\n";
            foreach ($assoc as $k => $v) {
                $v = $printBigAssoc($v, $t + 1);
                if ($is_associative) {
                    $k = "<span style=\"font-weight: bold; \">{$k}</span>";
                }
                $contenido .= "\n                    <div style=\"margin-left: {$mt}px; position: relative; top: 0px; left: 0px; \">\n                       {$k} : {$v}\n                    </div>\n                ";
            }
            return $contenido . "</div>\n";
        }
        if (is_bool($assoc)) {
            return $assoc ? 'TRUE' : 'FALSE';
        }
        if (is_null($assoc)) {
            return 'NULL';
        }
        return $assoc;
    };
    $title = $title ? "<div style=\"position: absolute; top: 3px; left: 10px; font-size: 15px; font-weight: bold; color: #666; \">{$title}</div>" : '';
    echo "<div style=\"position: absolute; top: 50px; right: 50px; width: 600px; height: 400px; border: 1px solid #000; background: #f0f0f0; \">" . $title . "<div style=\"position: absolute; top: 5px; right: 12px; font-size: 15px; font-weight: bold; color: #666; \">" . printSize(sizeofvar($var)) . "</div>" . "<div style=\"position: absolute; top: 28px; left: 10px; right: 10px; bottom: 10px; overflow: auto; font-size: 13px; \">" . $printBigAssoc($var) . "</div>" . "</div>";
}
Example #3
0
 function processLine($buffer)
 {
     if (!$this->inParams) {
         $markerPos = strpos($buffer, APIV3_START_MARKER);
         if ($markerPos !== false) {
             $explodedBuffer = explode(' ', $buffer);
             $this->ipAddress = substr($explodedBuffer[3], 1, -1);
             $this->params = substr($buffer, $markerPos + strlen(APIV3_START_MARKER));
             $this->inParams = true;
             $this->isFeed = false;
             return false;
         }
         $markerPos = strpos($buffer, APIV3_GETFEED_MARKER);
         if ($markerPos !== false) {
             $explodedBuffer = explode(' ', $buffer);
             $this->ipAddress = substr($explodedBuffer[3], 1, -1);
             $this->params = substr($buffer, $markerPos + strlen(APIV3_GETFEED_MARKER));
             $this->inParams = true;
             $this->isFeed = true;
             return false;
         }
     } else {
         if ($buffer[0] == ']') {
             $this->inParams = false;
             $parsedParams = print_r_reverse($this->params);
             if (print_r($parsedParams, true) != $this->params) {
                 print "print_r_reverse failed\n";
                 return false;
             }
             if ($this->isFeed) {
                 $shouldQuit = processFeedRequest($this->ipAddress, $parsedParams);
             } else {
                 $shouldQuit = processRequest($this->ipAddress, $parsedParams);
             }
             if ($shouldQuit) {
                 return true;
             }
         } else {
             $this->params .= $buffer;
         }
     }
     return false;
 }