小编tro*_*ter的帖子

在PHP中,可以在变量中使用函数

我知道在php中你可以在变量中嵌入变量,比如:

<? $var1 = "I\'m including {$var2} in this variable.."; ?>
Run Code Online (Sandbox Code Playgroud)

但我想知道如何,以及是否可以在变量中包含一个函数.我知道我可以写:

<?php
$var1 = "I\'m including ";
$var1 .= somefunc();
$var1 = " in this variable..";
?>
Run Code Online (Sandbox Code Playgroud)

但是如果我有一个很长的变量输出,我不想每次都这样做,或者我想使用多个函数:

<?php
$var1 = <<<EOF
    <html lang="en">
        <head>
            <title>AAAHHHHH</title>
            <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
        </head>
        <body>
            There is <b>alot</b> of text and html here... but I want some <i>functions</i>!
            -somefunc() doesn't work
            -{somefunc()} doesn't work
            -$somefunc() and {$somefunc()} doesn't work of course because a function needs to be a string
            -more non-working: ${somefunc()}
        </body> …
Run Code Online (Sandbox Code Playgroud)

html php variables function

10
推荐指数
1
解决办法
1万
查看次数

标签 统计

function ×1

html ×1

php ×1

variables ×1