thinkphp dump function
/** * Browser-friendly variable output * @param mixed $var variable * @param boolean $echo whether the output default is true if False returns the output string * @param string $label label defaults to NULL * @param boolean $strict preciseness default to True * @return void|string/function Dump ($var, $ech O = true, $label = null, $strict = True) {$label = (Null = = = $label)? ': RTrim ($label).
' ';
if (! $strict) {if (Ini_get (' html_errors ')) {$output = Print_r ($var, true); $output = ' <pre> '. $label. Htmlspecialchars ($output, ent_quotes).
' </pre> ';
else {$output = $label. Print_r ($var, true);
} else {Ob_start ();
Var_dump ($var);
$output = Ob_get_clean ();
if (!extension_loaded (' Xdebug ')) {$output = Preg_replace ('/\]\=\>\n (\s+)/M ', '] => ', $output); $output = ' <pre> '. $label. Htmlspecialchars ($output, ent_quotes).
' </pre> ';
} if ($echo) {echo ($output);
return null;
else {return $output; }
}
Test code
$a = ' Chinese ';
$a = Iconv ("UTF-8", "GB2312", $a);
Dump ($a);
echo "
Test results
It is found that only var_dump have output, while dump has no output.
Error analysis, positioning htmlspecialchars
Tracing the debug function, you can detect the problem in the Htmlspecialchars function.
Official website Description: 5.4 Before version the default encoding for this function is the iso-8859-1,5.4 and 5.5 version after the default encoding is utf-8,5.6, and the configuration encoding is used as the default encoding. P>
Here PHP Version 5.6.21, the encoding used by Htmlspecialchars is the encoding of the configuration item, as follows:
Htmlspecialchars uses UTF-8 encoding, and there is no output for strings encoded in Chinese such as gbk,gb2312. There is no output as long as the string in the Htmlspecialchars function argument contains a GBK or gb2312 encoded character. The test is as follows:
$b = ' Chinese abc ';
$a = Iconv ("UTF-8", "GB2312", $b);
$c = $b. $a;
Var_dump (Htmlspecialchars ($a, ent_quotes)); No output
var_dump (Htmlspecialchars ($b, ent_quotes))//Output normal
var_dump (Htmlspecialchars ($c, ent_quotes));// No output
Solution
$b = ' Chinese abc ';
$a = Iconv ("UTF-8", "GB2312", $b);
$c = $b. $a;
Var_dump (Htmlspecialchars ($a, ent_quotes, ' iso-8859-1 ')); There is output, gb2312 encoding Chinese garbled
var_dump (Htmlspecialchars ($b, ent_quotes, ' iso-8859-1 '));/output normal
var_dump ( Htmlspecialchars ($c, ent_quotes, ' iso-8859-1 ')); Have output, gb2312 encoded Chinese garbled
So the Htmlspecialchars function in the thinkphp dump function plus the default encoding iso-8859-1 can be.
The above thinkphp dump function without output instance code is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.