gpt4 book ai didi

PHP 表达式 <<
转载 作者:IT王子 更新时间:2023-10-29 00:10:53 26 4
gpt4 key购买 nike

我已经使用 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/

26 4 0

Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com