Sé que en php puede incrustar las variables dentro de las variables, como:En PHP es posible el uso de una función dentro de una variable
<? $var1 = "I\'m including {$var2} in this variable.."; ?>
pero me preguntaba cómo, y si era posible incluir una función dentro de una variable. Sé que solo podría escribir:
<?php
$var1 = "I\'m including ";
$var1 .= somefunc();
$var1 = " in this variable..";
?>
Pero lo que si tengo una variable de largo para la salida, y yo no quiero hacer esto cada vez, o quiero usar múltiples funciones:
<?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>
</html>
EOF;
?>
O quiero cambios dinámicos en que la carga de código:
<?
function somefunc($stuff) {
$output = "my bold text <b>{$stuff}</b>.";
return $output;
}
$var1 = <<<EOF
<html lang="en">
<head>
<title>AAAHHHHH</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>
<body>
somefunc("is awesome!")
somefunc("is actually not so awesome..")
because somefunc("won\'t work due to my problem.")
</body>
</html>
EOF;
?>
bien?
$ var1 = "Incluí {$ var2} en esta variable ..."; ?> ¿Por qué se está escapando una sola cita dentro de comillas dobles? ;) – Till