- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我已经使用 PHP 开发了几年了,最近遇到了这段代码:
<?php
echo <<<EOB
<html>
<head>
<title>My title</title>
</head>
...
EOB;
?>
我从未见过这种打印 HTML 的方法,它似乎非常有用,而且不太容易出现一些奇怪的变量或双引号语法错误。
我搜索了一些关于这个的官方信息,只找到了一篇关于 Rasmus 的帖子。
关于此功能的详细说明是什么?EOB 是什么意思?也许 block 结束?
最佳答案
这被称为 heredoc句法。该文档将告诉您您需要知道的一切。
但是,本质上:
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.
所以 EOB
正是作者选择的分隔符,不太确定它在他的情况下代表什么,但标识符可以是任何你想要的。
关于PHP 表达式 <<<EOB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1048481/
我已经使用 PHP 开发了几年了,最近遇到了这段代码: My title ... EOB; ?> 我从未见过这种打
我最近在这个上下文中遇到了 Ruby EOB/-EOB 构造(来自 Ruby id3 library): def initialize(...) # ... instance_eval "v
我是一名优秀的程序员,十分优秀!