ich in PHP kennen verwenden Sie Variablen innerhalb von Variablen einbetten können, wie:In PHP ist es möglich, eine Funktion innerhalb einer Variablen
<? $var1 = "I\'m including {$var2} in this variable.."; ?>
Aber ich frage mich, wie und ob es möglich war, eine Funktion schließen innerhalb einer Variablen. Ich weiß, ich könnte nur schreiben:
<?php
$var1 = "I\'m including ";
$var1 .= somefunc();
$var1 = " in this variable..";
?>
Aber was, wenn ich eine lange Variable für die Ausgabe, und ich möchte nicht diese jedes Mal tun, oder ich will mehrere Funktionen verwenden:
<?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;
?>
Oder ich möchte dynamische Änderungen in dieser Last von Code:
<?
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;
?>
Nun?
$ var1 = "Ich schließe {$ var2} in dieser Variable ein."; ?> Warum entkommst du ein einzelnes Zitat in Anführungszeichen? ;) – Till