之前一直用firephp来调试php,主要受限Firefox启动太慢,研究了下chromephp;
写了个简单的判断模版:
<?php /** * @Author: Klaus * @Date: 2016-01-16 10:23:44 * @Last Modified by: Administrator * @Last Modified time: 2016-01-26 16:51:53 */ // 判断当前浏览器 if (strpos($_SERVER["HTTP_USER_AGENT"], ‘MSIE8.0‘)) { $browser = ‘IE8‘; } else if (strpos($_SERVER["HTTP_USER_AGENT"], ‘MSIE7.0‘)) { $browser = ‘IE7‘; } else if (strpos($_SERVER["HTTP_USER_AGENT"], ‘MSIE6.0‘)) { $browser = ‘IE6‘; } else if (strpos($_SERVER["HTTP_USER_AGENT"], ‘Firefox / 3‘)) { $browser = ‘Firefox‘; } else if (strpos($_SERVER["HTTP_USER_AGENT"], ‘Firefox / 2‘)) { $browser = ‘Firefox‘; } else if (strpos($_SERVER["HTTP_USER_AGENT"], ‘Chrome‘)) { $browser = ‘Chrome‘; } else if (strpos($_SERVER["HTTP_USER_AGENT"], ‘Safari‘)) { $browser = ‘Safari‘; } else if (strpos($_SERVER["HTTP_USER_AGENT"], ‘Opera‘)) { $browser = ‘Opera‘; } else { $browser = $_SERVER["HTTP_USER_AGENT"]; } if ($browser == ‘Chrome‘) { require ‘ChromePhp.php‘; function fb($a, $b = ‘‘) { if ($b) { return ChromePhp::log($a . ":", $b); } else { $name = ‘$‘ . array_search($a, $GLOBALS, true); //获取变量名字 // var_dump($name); return ChromePhp::log($name . ":", $a); } } $aaa = "ChromePhp.php开启了!"; fb(‘$aaa‘, $aaa); fb($aaa); } else { require ‘FirePHPCore/fb.php‘; $a = "firephp开启了!"; fb($a, "php调试"); }
其中自动判断浏览器,网上找的哈!
后续主要优化多个输出,导致不知道是那个变量,所以做了个获取变量名字的,网上有个function,但是我觉得变量名字重复的可能性不大,所以就简化了些;
测试效果如下:
Chrome:
Firefox:
其中插件方面 Chrome :Chrome Logger 用的时候需要点击下插件按钮开启,这个没有firephp方便;
Chromephp下载:https://github.com/ccampbell/chromephp
希望大家多多提提意见哈!
时间: 2024-10-29 19:10:55