예제 #1
0
 /**
  *	Output var dump to string.
  *	@param  array	$var	variable
  *	@param  string	$title	variable title
  *	@param  bool	$sort	if array than sort?
  *	@param  bool	$first	for static function use only
  *	@return string
  */
 static function dump($var, $title = '', $sort = false, $first = true)
 {
     $str = '';
     $size = '';
     if (is_object($var)) {
         $var = (array) $var;
     }
     if (is_array($var)) {
         $size = count($var);
     } else {
         if (is_string($var)) {
             $size = strlen($var);
             if ($size > 200) {
                 $var = v::cutStr($var, 20);
             }
         }
     }
     $str .= '<li style="padding-left: 20px">' . ($title ? '[ <b style="color:#009">' . $title . '</b> ]' : '') . ' ( ' . gettype($var) . ' ' . $size . ') ';
     if (is_array($var)) {
         if ($sort) {
             asort($var);
         }
         if (count($var)) {
             $str .= '<ul style="padding-left: 20px">';
             foreach ($var as $k => $v) {
                 $str .= v::dump($v, is_numeric($k) ? $k + 1 : $k, $sort, false);
             }
             $str .= '</ul>';
         }
     } else {
         if (!is_object($var) and $var) {
             $str .= ' <b style="color:#090">' . htmlspecialchars(str_replace('=[', '\\=\\[', $var)) . '</b>';
         }
     }
     $str .= '</li>';
     if ($first && $str) {
         $str = '<ul style="padding: 0px">' . $str . '</ul>';
     }
     return $str;
 }