回声网络_PHP的回声

回声网络

PHP is often used to generate small “snippets” of content, often through the echo function. Just where and how echo is used is a matter of both efficiency and (to a lesser degree) personal style.

PHP通常用于通过echo功能生成小的“片段”内容。 在何处以及如何使用 echo是效率和(在较小程度上)个人风格的问题。

One option is to echo both the content and the HTML surrounding it:

一种选择是同时显示内容和周围HTML:

<?php echo '<p>Some dynamic content here</p>' ?>

…or you could place the HTML code outside the , which is usually my preferred solution, especially when combined with a PHP shortcut for echo:

…或者您可以将HTML代码放置在 之外 ,这通常是我的首选解决方案,尤其是当与echoPHP快捷方式结合使用时:

<p><?='Some dynamic content here'?></p>

Neither approach is “wrong”: your chosen solution depends on which one is more efficient.

两种方法都不是“错误的”:您选择的解决方案取决于哪种方法更有效。

There is one final consideration we might make. PHP runs without any awareness of the HTML code before or after it; because of that, the code it generates, while perfectly valid, may not be formatted terribly well when you use "View Source" in your browser. If this is important to you, use "escape characters" in your code:

我们可能要作最后的考虑。 PHP在运行之前或之后都不会对HTML代码有任何了解; 因此,当您在浏览器中使用“查看源代码”时,它生成的代码虽然完全有效,但可能无法很好地格式化。 如果这对您很重要,请在代码中使用“转义符”:

<?php echo '<p>Test content here</p>\n' ?>

That \n forces PHP to create a new line after it executes, making your code more readable. Escapes may also be used before characters that might otherwise be interpreted incorrectly: for example, if in the above line, it we wanted to say “Test text's here” we would alter our PHP code to:

\n强制PHP执行后创建新行,使您的代码更具可读性。 还可以在可能会被错误解释的字符之前使用转义符:例如,如果在上一行中,我们想要说“ Test text's here”,则可以将我们PHP代码更改为:

<?php echo '<p>Test text\'s here</p>\n' ?>

In this case the backwards slash character tells PHP that that apostrophe is “real” and is not a single quote that will terminate our code prematurely.

在这种情况下,反斜杠字符告诉PHP撇号是“真实的”,并且不是单引号,它将导致我们的代码过早终止。

Interweaving , HTML and CSS is a very powerful technique, but you must be clear on where each begins and ends in order to produce a whole, complete and valid page.

HTMLCSS交织是一种非常强大的技术,但是您必须清楚地知道它们的开始和结束位置,以便生成一个完整,完整和有效的页面。

翻译自: https://thenewcode.com/120/PHP-echo

回声网络

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值