मैं php में पता अंदर एक समारोह का उपयोग करने के चर के अंदर चर एम्बेड कर सकते हैं, जैसे कि यह संभव है:PHP में एक चर
<? $var1 = "I\'m including {$var2} in this variable.."; ?>
लेकिन मैं सोच रहा था कि कैसे, और अगर यह संभव हो गया था एक समारोह में शामिल करने के एक चर के अंदर। मैं जानता हूँ कि मैं सिर्फ लिख सकते हैं:
<?php
$var1 = "I\'m including ";
$var1 .= somefunc();
$var1 = " in this variable..";
?>
लेकिन क्या होगा अगर मैं उत्पादन के लिए एक लंबे चर है, और मैं इस पर हर बार ऐसा नहीं करना चाहते हैं, या क्या मैं बहुत से कार्यों का उपयोग करना चाहते हैं:
<?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;
?>
या मैं कोड की है कि लोड में गतिशील परिवर्तन चाहते हैं:
<?
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;
?>
खैर?
$ var1 = "मैं इस चर में {$ var2} समेत हूं .."; ?> आप डबल कोट्स के अंदर एक ही उद्धरण से क्यों बच रहे हैं? ;) – Till