Krumo::_string PHP Method

_string() private static method

Render a dump for a string value
private static _string ( mixed $data, string $name )
$data mixed
$name string
    private static function _string($data, $name)
    {
        $collapsed = static::_isCollapsed(static::$_level, 1);
        if ($collapsed) {
            $collapse_style = 'style="display: none;"';
        } else {
            $collapse_style = '';
        }
        // extra
        $_ = $data;
        // Get the truncate length from the config, or default to 100
        $truncate_length = static::_config('display', 'truncate_length', 100);
        $display_cr = static::_config('display', 'carriage_returns', true);
        $strlen = strlen($data);
        if (function_exists('mb_strlen')) {
            $strlen = mb_strlen($data, static::getCharset());
        }
        if ($strlen > $truncate_length) {
            if (function_exists('mb_substr')) {
                $_ = mb_substr($data, 0, $truncate_length - 1, static::getCharset());
            } else {
                $_ = substr($data, 0, $truncate_length - 1);
            }
            $_extra = true;
        } else {
            $_extra = false;
        }
        $icon = '';
        // Check to see if the line has any carriage returns
        if (preg_match("/\n|\r/", $data)) {
            $slash_n = substr_count($data, "\n");
            $slash_r = substr_count($data, "\r");
            $title = "Note: String contains ";
            if ($slash_n) {
                $title .= "{$slash_n} " . static::plural($slash_n, "new line");
            }
            if ($slash_n && $slash_r) {
                $title .= " and ";
            }
            if ($slash_r) {
                $title .= "{$slash_r} " . static::plural($slash_r, "carriage return");
            }
            $icon = static::get_icon("information", $title);
            // We flag this as extra so the dropdown can show the correctly formatted version
            $_extra = true;
        }
        $_ = htmlentities($_);
        // Convert all the \r or \n to visible paragraph markers
        if ($display_cr) {
            $_ = preg_replace("/(\\r\\n|\\n|\\r)/", "<strong class=\"krumo-carrage-return\"> &para; </strong>", $_);
        } else {
            $_ = nl2br($_);
        }
        $expand_class = '';
        if ($_extra) {
            $expand_class = 'krumo-expand';
        }
        print "<li class=\"krumo-child\">";
        print "<div class=\"krumo-element {$expand_class}\" ";
        if ($_extra) {
            print " onClick=\"krumo.toggle(this);\" ";
        }
        print "onMouseOver=\"krumo.over(this);\" onMouseOut=\"krumo.out(this);\">\n";
        print "<a class=\"krumo-name\">{$name}</a> ";
        print "<em class=\"krumo-type\">String(<strong class=\"krumo-string-length\">" . strlen($data) . "</strong>)</em> {$icon}";
        print static::get_separator() . " <strong class=\"krumo-string\">" . $_;
        // This has to go AFTER the htmlspecialchars
        if (strlen($data) > $truncate_length) {
            print "&hellip;";
        }
        print "</strong>";
        $ut = static::is_datetime($name, $data);
        if ($ut) {
            print " ~ <strong class=\"krumo-datetime\">{$ut}</strong>";
        }
        // callback
        if (is_callable($data)) {
            print "<span class=\"krumo-callback\"> | ";
            print "(<em class=\"krumo-type\">Callback</em>) <strong class=\"krumo-string\">" . htmlSpecialChars($_) . "()</strong></span>";
        }
        print "</div>";
        if ($_extra) {
            $data = htmlentities($data);
            $data = nl2br($data);
            print "<div class=\"krumo-nest\" {$collapse_style}>";
            print "<ul class=\"krumo-node\">";
            print "<li class=\"krumo-child\"> <div class=\"krumo-preview\">" . $data . "</div></li>";
            print "</ul></div>";
        }
        print "</li>";
    }

Usage Example

Beispiel #1
0
 /**
  * Dump information about a variable
  *
  * @param mixed $data
  * @param string $name
  * @access private
  * @static
  */
 private static function _dump(&$data, $name = '…')
 {
     // Highlight elements that have a space in their name.
     // Spaces are hard to see in the HTML and are hard to troubleshoot
     $name = Krumo::sanitize_name($name);
     // object
     if (is_object($data)) {
         return Krumo::_object($data, $name);
     }
     // array
     if (is_array($data)) {
         return Krumo::_array($data, $name);
     }
     // resource
     if (is_resource($data)) {
         return Krumo::_resource($data, $name);
     }
     // scalar
     if (is_string($data)) {
         return Krumo::_string($data, $name);
     }
     // float
     if (is_float($data)) {
         return Krumo::_float($data, $name);
     }
     // integer
     if (is_integer($data)) {
         return Krumo::_integer($data, $name);
     }
     // boolean
     if (is_bool($data)) {
         return Krumo::_boolean($data, $name);
     }
     // null
     if (is_null($data)) {
         return Krumo::_null($name);
     }
 }