php 如何在不同的行上显示 print_r?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8516352/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I display print_r on different lines?
提问by ssvarc
When I run the following code:
当我运行以下代码时:
echo $_POST['zipcode'];
print_r($lookup->query($_POST['zipcode']));
?>
the results are concatenated on one line like so: 10952Array
.
结果被连接在同一行,像这样:10952Array
。
How can I get it to display on separate lines, like so:
如何让它显示在单独的行上,如下所示:
08701
Array
回答by span
You might need to add a linebreak:
您可能需要添加换行符:
echo $_POST['zipcode'] . '<br/>';
If you wish to add breaks between print_r() statements:
如果您希望在 print_r() 语句之间添加中断:
print_r($latitude);
echo '<br/>';
print_r($longitude);
回答by Sen Sokha
to break line with print_r:
用 print_r 换行:
echo "<pre>";
print_r($lookup->query($_POST['zipcode']));
echo "</pre>";
The element will format it with any pre-existing formatting, so \n will turn into a new line, returned lines (when you press return/enter) will also turn into new lines.
该元素将使用任何预先存在的格式对其进行格式化,因此 \n 将变成一个新行,返回的行(当您按 return/enter 时)也将变成新行。
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre
回答by Jigar Tank
Just echo these : echo $_POST['zipcode']."<br/>";
只是回应这些: echo $_POST['zipcode']."<br/>";
回答by Manngo
Old question, but I generally include the following function with all of my PHP:
老问题,但我通常在我的所有 PHP 中都包含以下函数:
The problem occurs because line breaks are not normally shown in HTML output. The trick is to wrap the output inside a pre
element:
出现此问题的原因是换行符通常不显示在 HTML 输出中。诀窍是将输出包装在一个pre
元素中:
function printr($data) {
echo sprintf('<pre>%s</pre>',print_r($data,true));
}
print_r(…, true)
returns the output without (yet) displaying it. From here it is inserted into the string using the printf
function.
print_r(…, true)
返回输出而不(还)显示它。从这里它使用printf
函数插入到字符串中。
回答by charel-f
If this is what your browser displays:
如果这是您的浏览器显示的内容:
Array ( [locus] => MK611812 [version] => MK611812.1 [id] => 1588040742 )
And this is what you want:
这就是你想要的:
Array
(
[locus] => MK611812
[version] => MK611812.1
[id] => 1588040742
)
the easy solution is to add the the <pre>
format to your code that prints the array:
简单的解决方案是将<pre>
格式添加到打印数组的代码中:
echo "<pre>";
print_r($final);
echo "</pre>";