脚本宝典收集整理的这篇文章主要介绍了你如何格式化PHP错误消息?他们不尊重CSS,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
例如
some code} else { echo "error,please do something!";
我如何得到(或很好地问)在我的CSS中已经存在的div中输出文本,以便它遵守该div附带的格式和对齐规则.
实际上,我刚刚意识到你所说的“错误”涉及回声/打印输出.这是问题所在.
您将字符串错误DIRECTLY打印(回显)到输出缓冲区(当您运行完所有代码时将HTML发送到浏览器). echo()和PRint()直接发送你正在回显/打印的内容,除非它在output_buffer块中(我不会把你的细节混淆).
因此,您正在管理常规的html /文本输出,以便不将页面内容打印到输出缓冲区,但在这种情况下,您使用的是echo,它将字符串数据直接发送到缓冲区AT That时刻.
例如:
<?PHP $mystr = "<html>"; $mystr .= "<body><h1>Hello World</h1></body></html>"; echo "<head></head>"; echo $mystr; ?>
哪个会给我输出到浏览器:
<head></head><html><body><h1>Hello World</h1></body></html>
我存储字符串数据,但在回显其他html数据之前回显HEAD块.
我需要做的是:
<?PHP $mystr = "<html>"; $mystr .= "<head></head>"; $mystr .= "<body><h1>Hello World</h1></body></html>"; echo $mystr; ?>
哪个会给我输出到浏览器:
<html><head></head><body><h1>Hello World</h1></body></html>
我存储字符串输出(在这种情况下你的错误),直到我需要稍后输出.这是您需要知道的,并在您的代码中完成.
我会研究error_reporting(0)/ display_errors,error_get_last和set_error_handler.
http://www.php.net/manual/en/function.error-reporting.php
http://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors
http://php.net/manual/en/function.error-get-last.php
http://www.php.net/manual/en/function.set-error-handler.php
这样你就可以立即停止将所有错误发送到输出缓冲区(这就是它位于页面顶部的原因),然后捕获,存储和显示错误.
error_reporting(0); set_error_handler('PHPLOGError'); function PHPLogError() { $error = error_get_last(); if ($error['tyPE'] == 1) { //do your stuff } } function PHPGetLoggedErrors() { // return your prettified html errors }
或者,换句话说……
<?PHP $GLOBAL['_logged_PHP_errors'] = array(); error_reporting(0); set_error_handler('PHPLogError'); function PHPLogError() { global $_logged_PHP_errors; $error = error_get_last(); if ($error['type'] == 1) { $_logged_PHP_errors[] = "<span>$error</span>"; } } function PHPGetLoggedErrors() { global $_logged_PHP_errors; return "<ol><li>".implode('</li><li>',$_logged_PHP_errors)."</li></ol>"; } ?>
other.PHP
<?PHP require_once 'PHP_error_handle.PHP'; // other stuff,pages included/required,etc...
只需确保在第一行代码中发生require_once.
以上是脚本宝典为你收集整理的你如何格式化PHP错误消息?他们不尊重CSS全部内容,希望文章能够帮你解决你如何格式化PHP错误消息?他们不尊重CSS所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。