PHP表达式<<< EOB [英] PHP expression <<<EOB

查看:384
本文介绍了PHP表达式<<< EOB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用PHP开发了好几年了,最近碰到了这段代码:

 <?php 
echo<<< EOB
< html>
< head>
< title>我的标题< / title>
< / head>
...
EOB;
?>

我从来没有见过这种打印HTML的方法,这看起来很有用,也不太容易一些奇怪的变量或双引号语法错误。



我搜索了一些有关这方面的官方信息,只发现了一篇关于Rasmus的文章。 b
$ b

什么是关于这个功能的详细解释和EOB是什么意思?也许结束块

解决方案

这就是所谓的 heredoc 语法。该文件将告诉你所有你需要知道的事情。



实际上,不过:


<第三种分隔字符串的方法是heredoc语法:<<< ;.在这个操作符之后,提供了一个标识符,然后是一个换行符。字符串本身,然后再次使用相同的标识符来关闭引用。



结束标识符必须从行的第一列开始。此外,标识符必须遵循与PHP中任何其他标签相同的命名规则:它必须仅包含字母数字字符和下划线,并且必须以非数字字符或下划线开头。


所以 EOB 就是作者选择的分隔符,而不是真的确定它在他的情况下代表什么,但标识符可以是任何你想要的。


I've been developing with PHP for some years now, and recently came across this code:

<?php
    echo <<<EOB
        <html>
        <head>
            <title>My title</title>
        </head>
        ...
    EOB;
?>

I've never seen this approach to print HTML, which seems to be pretty useful and less prone to some weird variable or double quote syntax error.

I've searched for some official information about this and only found a post of Rasmus talking about this.

What is a detailed explanation about this functionality and what does EOB mean? Maybe end of block?

解决方案

This is known as heredoc syntax. The documentation will tell you everything you need to know.

Essentially, however:

A third way to delimit strings is the heredoc syntax: <<<. After this operator, an identifier is provided, then a newline. The string itself follows, and then the same identifier again to close the quotation.

The closing identifier must begin in the first column of the line. Also, the identifier must follow the same naming rules as any other label in PHP: it must contain only alphanumeric characters and underscores, and must start with a non-digit character or underscore.

So EOB is just what the author chose as his delimiter, not really sure what it stands for in his case but the identifier can be whatever you want.

这篇关于PHP表达式&lt;&lt;&lt; EOB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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