Detailed explanation of PHP's delimiter heredoc technology

小云云
Release: 2023-03-21 20:26:01
Original
1408 people have browsed it

在正规的PHP文档中和技术书籍中一般没有详细讲述,只是提到了这是一种Perl风格的字符串输出技术。但是现在的一些论坛程序,和部分文章系统,都巧妙的使用heredoc技术,来部分的实现了界面与代码的准分离,phpwind模板就是一个典型的例子。

1.以<<

2.位于开始标记和结束标记之间的变量可以被正常解析,但是函数则不可以。在heredoc中,变量不需要用连接符.或,来拼接,如下:

$v=2; $a= <<
        
Copy after login

3.heredoc常用在输出包含大量HTML语法d文档的时候。比如:函数outputhtml()要输出HTML的主页。可以有两种写法。很明显第二种写法比较简单和易于阅读。

function outputhtml(){ echo ""; echo "主页
"; echo "主页内容"; echo "; } function outputhtml() { echo << 主页
 主页内容  EOT; } outputhtml();
Copy after login

点击打开链接

PHP定界符<<

PHP定界符 多行字符串的生成

PHP 定界符 使用技巧_PHP教程

The above is the detailed content of Detailed explanation of PHP's delimiter heredoc technology. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!