这个符号“<<<HTML”是什么意思?
What does this symbol "<<<HTML" mean?
在阅读另一个程序员的代码时,我遇到了 <<<H.TML
符号。同事说是用来在php文件里面写html。
我试图找到有关其用法的更多详细信息,但没有找到太多。请任何人向我解释它是如何工作的以及它叫什么?
public function SetContent($page = '') {
$this->_header->SetPageNavigation($page) ;
$budgetHTML = '';
$signup1 = '';
$GetHeader = $this->_header->GetHeader() ;
$GetFooter = $this->_footer->GetFooter() ;
$DocType = <<<HTML
<!DOCTYPE html>
<!--[if IE 8]> <html class="no-js ie8 ie" lang="en"> <![endif]-->
<!--[if IE 9]> <html class="no-js ie9 ie" lang="en"> <![endif]-->
<!--[if gt IE 9]><![endif]-->
HTML;
$this->_html = sprintf("{$DocType}<html>");
$this->_html .= sprintf("%s", $this->_head->GetHTML());
$bg=$this->_common->getBgImage();
$bg=json_decode($bg);
if(!empty($bg->BGImage)&&(file_exists($GLOBALS['DocumentRoot'].'/bgImages/'.$bg->BGImage)))
{
$backgroundImage='background: url('.$GLOBALS['DOCUMENT_ROOT'].'/bgImages/'.$bg->BGImage.') no-repeat fixed top center;background-size: cover !important;';
}
else
{
$backgroundImage='';
}
$this->_html .= sprintf( '<body style="'.$backgroundImage.'" >
<noscript>
<h1 style="color:red; text-align:center; padding-top:100px;">This page needs JavaScript activated to work</h1>
<style>div { display:none; }</style>
</noscript>
<div class="loading"><img src="'.$GLOBALS['RootURL'].'images/main-loader.GIF" width="128" height="128" ></div>
<div id="wrapper"><div class="page-bg">%s%s%s%s<div class="clear"></div></div></div>', $GetHeader, $budgetHTML, $this->_maincontenthtml, $GetFooter);
$this->_html .= sprintf("</body>");
}
是的,当你想在 PHP 变量中使用大内容作为字符串时,它在 PHP 语法中使用,然后你可以使用 heredoc syntax
语法
示例:
<?php
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
您正在查看的内容叫做 heredoc。
当您不想使用引号时,它用于声明一个长字符串文字。来自 PHP 文档:
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
在您的情况下,他们使用 HTML
作为该符号而不是 EOD
。它实际上与 HTML 完全无关,但如果您愿意,可以将一大块 HTML 分配给变量,就像任何其他字符串文字值一样。
它是一个 heredoc.it 允许人们轻松地从 PHP 中写入大量文本,而不需要不断地转义 things.Heredoc 是一个很好的替代引用字符串是因为增加了可读性和可维护性。您不必转义引号和(好)IDE 或文本编辑器将使用正确的语法突出显示。
一个非常常见的例子:从 PHP:
中回显 HTML
$html = <<<HTML
<div class='something'>
<ul class='mylist'>
<li>$something</li>
<li>$whatever</li>
<li>$testing123</li>
</ul>
</div>
HTML;
// sometime later
echo $html;
在阅读另一个程序员的代码时,我遇到了 <<<H.TML
符号。同事说是用来在php文件里面写html。
我试图找到有关其用法的更多详细信息,但没有找到太多。请任何人向我解释它是如何工作的以及它叫什么?
public function SetContent($page = '') {
$this->_header->SetPageNavigation($page) ;
$budgetHTML = '';
$signup1 = '';
$GetHeader = $this->_header->GetHeader() ;
$GetFooter = $this->_footer->GetFooter() ;
$DocType = <<<HTML
<!DOCTYPE html>
<!--[if IE 8]> <html class="no-js ie8 ie" lang="en"> <![endif]-->
<!--[if IE 9]> <html class="no-js ie9 ie" lang="en"> <![endif]-->
<!--[if gt IE 9]><![endif]-->
HTML;
$this->_html = sprintf("{$DocType}<html>");
$this->_html .= sprintf("%s", $this->_head->GetHTML());
$bg=$this->_common->getBgImage();
$bg=json_decode($bg);
if(!empty($bg->BGImage)&&(file_exists($GLOBALS['DocumentRoot'].'/bgImages/'.$bg->BGImage)))
{
$backgroundImage='background: url('.$GLOBALS['DOCUMENT_ROOT'].'/bgImages/'.$bg->BGImage.') no-repeat fixed top center;background-size: cover !important;';
}
else
{
$backgroundImage='';
}
$this->_html .= sprintf( '<body style="'.$backgroundImage.'" >
<noscript>
<h1 style="color:red; text-align:center; padding-top:100px;">This page needs JavaScript activated to work</h1>
<style>div { display:none; }</style>
</noscript>
<div class="loading"><img src="'.$GLOBALS['RootURL'].'images/main-loader.GIF" width="128" height="128" ></div>
<div id="wrapper"><div class="page-bg">%s%s%s%s<div class="clear"></div></div></div>', $GetHeader, $budgetHTML, $this->_maincontenthtml, $GetFooter);
$this->_html .= sprintf("</body>");
}
是的,当你想在 PHP 变量中使用大内容作为字符串时,它在 PHP 语法中使用,然后你可以使用 heredoc syntax
语法
示例:
<?php
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
您正在查看的内容叫做 heredoc。
当您不想使用引号时,它用于声明一个长字符串文字。来自 PHP 文档:
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
在您的情况下,他们使用 HTML
作为该符号而不是 EOD
。它实际上与 HTML 完全无关,但如果您愿意,可以将一大块 HTML 分配给变量,就像任何其他字符串文字值一样。
它是一个 heredoc.it 允许人们轻松地从 PHP 中写入大量文本,而不需要不断地转义 things.Heredoc 是一个很好的替代引用字符串是因为增加了可读性和可维护性。您不必转义引号和(好)IDE 或文本编辑器将使用正确的语法突出显示。
一个非常常见的例子:从 PHP:
中回显 HTML$html = <<<HTML
<div class='something'>
<ul class='mylist'>
<li>$something</li>
<li>$whatever</li>
<li>$testing123</li>
</ul>
</div>
HTML;
// sometime later
echo $html;