如何正确使用print_r或var_dump? [英] How do I properly use print_r or var_dump?

查看:130
本文介绍了如何正确使用print_r或var_dump?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在调试时经常使用以下代码段:

I use the following snippet quite often when I am debugging:

echo "<pre>" . var_dump($var) . "</pre>";

我发现我通常会得到一个很好的可读输出.但是有时候我就是不这样.这个例子让我特别烦恼:

And I find I usually get a nice readable output. But sometimes I just don't. I'm particularly vexed at the moment by this example:

<?php

$username='xxxxxx';
$password='xxxxxx';

$data_url='http://docs.tms.tribune.com/tech/tmsdatadirect/schedulesdirect/tvDataDelivery.wsdl';
$start=gmdate("Y-m-d\TH:i:s\Z",time());
$stop =gmdate("Y-m-d\TH:i:s\Z",time()+3600*24);

$client = new SoapClient($data_url, array('exceptions' => 0,
                                          'user_agent' => "php/".$_SERVER[SCRIPT_NAME],
                                          'login'      => strtolower($username),
                                          'password'   => $password));
$data = $client->download($start,$stop);

print_r($data);

?>

我当然不想透露自己的凭据,但是我被告知在这种情况下,print_r将与我的常规代码段相同,而事实上,print_r和我的代码段都不会产生任何非运行时数据,而不会格式化.我怎样才能使它漂亮?!

I don't want to reveal my credentials of course, but I am told print_r in this case will do the same as my usual snippet when in fact neither print_r nor my snippet produce anything other than runon data with no formatting at all. How can I make it pretty?!

推荐答案

var_dump总是向您显示格式化数据中的数组,但有太多多余的东西

var_dump always show you array in formatted data but too much extra stuff

var_dump($data);

但是如果您想在此处格式化数据,则需要使用<pre>标签

but if you want formatted data here you need to use <pre> tags

echo '<pre>';
print_r($data);
echo '</pre>';

这篇关于如何正确使用print_r或var_dump?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆