我如何从PHP开始一个新的HTML行? [英] How do I start a new HTML line from PHP?

查看:84
本文介绍了我如何从PHP开始一个新的HTML行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我PHP循环中的代码:

  echo'Name:'。 $名称。 <峰; br />; 

如何让PHP在循环的每次迭代中开始新的HTML行(而不是打印所有内容到一行HTML代码中)?

解决方案

您需要在输出中包含换行符。因此:

  echo'Name:'。 $名称。 <峰; br /> \\\
;

请注意双引号,它是转义的\ n显示为换行符所必需的字符\\\



另一个有用的转义是\t,它将标签插入到输出中。



<最后,作为一个不相关的提示,使用逗号而不是句点将多个字符串传递给 echo 的速度会更快,如下所示:

  echo'Name:',$ name,< br /> \\\
;

这是因为使用点导致PHP分配一个新的字符串缓冲区,复制所有单独的字符串进入该缓冲区,然后输出这个组合字符串;而逗号导致PHP只是一个接一个地输出字符串。


This is the code inside my PHP loop:

echo 'Name: ' . $name . '<br/>';

How do I cause the PHP to begin a new HTML line with each iteration of the loop (instead of printing everything on a single HTML line)?

解决方案

You need to include newline characters in your output. Thus:

echo 'Name: ' . $name . "<br/>\n";

Note the double quotes, which are necessary for the escaped \n to appear as a newline character instead of a literal \n.

Another useful escape is \t, which inserts tabs into your output.

Lastly, as an unrelated tip, it is faster to pass multiple strings to echo with commas instead of periods, like so:

echo 'Name: ', $name ,"<br/>\n";

This is because using the dot causes PHP to allocate a new string buffer, copy all of the separate strings into that buffer, and then output this combined string; whereas the comma causes PHP to simply output the strings one after another.

这篇关于我如何从PHP开始一个新的HTML行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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