php 相当于 coldfusion cfsavecontent

标签 php coldfusion

我正在尝试将我每天在 coldfusion 中使用的 coldfusion 基础站点模板转换为 php。

在 coldfusion 中,我有一个 cfsavecontent,其中包含我显示的数据 block 。

这是一个例子:

       <cfoutput>
    <cfsavecontent variable="content">
        <div class="container-fluid content">
            <h3>Hello World</h3>

        </div>
        <cfinclude template="modal/modal.cfm">
    </cfsavecontent>
</cfoutput>

<cfinclude template="includes/template.cfm">

cfsavecontent 的 php 版本是什么。或者有可能吗?

谢谢。

最佳答案

给定这个 CFML:

<cfsavecontent variable="content">
    Some text<br>
    <cfif randRange(0,1)>
        <cfset result = "value if true">
    <cfelse>
        <cfset result = "and if it's false">
    </cfif>
    <cfoutput>#result#</cfoutput><br>
    Message from include is:
    <cfinclude template="./inc.cfm">
</cfsavecontent>

<cfoutput>#content#</cfoutput>

包括:

<cfset greeting = "G'day">
<cfoutput>#greeting#</cfoutput><br>

PHP 类似物是:

<?php
ob_start();
echo "Some text" . PHP_EOL;
if (rand(0,1)){
    $result = "value if true";
}else{
    $result = "and if it's false";
}
echo $result . PHP_EOL;
echo "Message from include is: ";
include __DIR__ . "\inc.php";

echo ob_get_clean();

inc.php:

<?php
$greeting = "G'day";
echo $greeting . PHP_EOL;

所以你想看看文档中的“Output Control Functions”。

关于php 相当于 coldfusion cfsavecontent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35848395/

相关文章:

coldfusion - 将超过 100 个参数传递给 ColdFusion 函数会引发错误

oop - 我应该为多个站点使用一个框架代码库还是为每个站点使用一个框架代码库?

tomcat - 从 JRun 4.0 转换到 Tomcat 有什么好处?

php - utf-8的问题

php - 使用 Php 我无法回显 HTML 表格

php - 用于匹配字母数字字符、下划线、句点和破折号的正则表达式,只允许在中间使用点和破折号

regex - Coldfusion ReReplace 电话号码重新格式化

php - Laravel 在 where 子句中加入 "and"和 "or"

php - 如何检测 "5 in a row"游戏中的对角线获胜 (PHP)

coldfusion - 尽管“启用空支持”已关闭,但在 cf2018 中启用了空