两个方便的php参数打印的方法

自动获取参数列,以及文件输出位置

//打印参数
function pog(){
	$arg = func_get_args();
	$backtrace=debug_backtrace();
	$actionflie=pathinfo($backtrace[0]['file']);
	foreach ($arg as $k=>$v){
		$arr[str_replace('.php','',$actionflie['basename'].':'.$backtrace[0]['line'].'.'.$k)]=$v;
	}
	$text = var_export ($arr,true);
	$text = preg_replace('/^array \(|,\s*\)$/', '', trim($text));
	$text = preg_replace('/^array \(|,\s*\)$/', '', trim($text));
	$text = preg_replace('/\=\>\s+array/m', ' => array', $text);
	$text = str_replace('\\\\', '/', $text);
	echo '<pre style="background-color:#eef;color:#000;font-family:Microsoft YaHei;font-size:14px;line-height:15px;padding:14px 0;">';
	print_r($arr);
	echo '

‘;

}

打印参数

function dog(){

$arr=array();

$arg=func_get_args();

$backe=debug_backtrace();

$pfile=pathinfo($backe[0][‘file’]);

foreach ($arg as $k=>$v){

$arr[str_replace(‘.php’,”,$actionflie[‘basename’].’:’.$backtrace[0][‘line’].’.’.$k)]=$v;

}

$str=var_export($arr,true);

$str=preg_replace(‘/(\n(.{4})+) \=> /’,”$1\t=> “,$str);

$str=preg_replace(‘/(\n(.{4})+.{1,4}) \=> /’,”$1\t\t=> “,$str);本贴由FastMVC首发,谢谢关注FastMVC。

$str=preg_replace(‘/\s+\=>\s+array \(/’,” => array (“,$str);

$str=preg_replace(‘/^array \(|,\s+\)$/’,””,$str);

echo ‘

';本贴由FastMVC首发,谢谢关注FastMVC。

echo $str;

echo '

‘;

}