[英]How to echo an echo in php?
我有一些基本的PHP代碼:
$raceramps56["short"] = "My Test Product";
$leftMenu =
'<div class="leftMenuProductButton"><?PHP echo $raceramps56["short"] ?></div>';
將不回顯PHP代碼,僅回顯元素。 我已經嘗試過類似的事情
<div class="leftMenuProductButton">' . <?PHP echo $raceramps56["short"] ?>. '</div>';
僅返回Parse error: parse error, unexpected '<'
所以我的問題是,如何使它起作用或采取另一種方法?
嘗試這個
$raceramps56["short"] = "My Test Product";
$leftMenu ='<div class="leftMenuProductButton">'.$raceramps56["short"].'</div>';
您可以在'中運行php。 如果您知道我的意思,就只能這樣回應。
$leftMenu ='<div class="leftMenuProductButton">.$raceramps56["short"].</div>';
echo $leftMenu;
用這個:
$leftMenu ='<div class="leftMenuProductButton">'.$raceramps56["short"].'</div>';
我以為我會提供一些額外的信息,以便您理解。
在您的代碼中:
$raceramps56["short"] = "My Test Product";
$leftMenu =
'<div class="leftMenuProductButton"><?PHP echo $raceramps56["short"] ?></div>';
您實際上是包括在內。
讀一讀。 http://php.net/manual/en/language.types.string.php
當我第一次學習時,我不理解文字'和雙引號之間的區別,尤其是在我試圖回聲時引起問題。
看看這個:
<?php
echo 'this is a simple string';
echo 'You can also have embedded newlines in
strings this way as it is
okay to do';
// Outputs: Arnold once said: "I'll be back"
echo 'Arnold once said: "I\'ll be back"';
// Outputs: You deleted C:\*.*?
echo 'You deleted C:\\*.*?';
// Outputs: You deleted C:\*.*?
echo 'You deleted C:\*.*?';
// Outputs: This will not expand: \n a newline
echo 'This will not expand: \n a newline';
// Outputs: Variables do not $expand $either
echo 'Variables do not $expand $either';
?>
如果使用“”代替“”,則不會獲得相同的輸出,因為“會解釋所有內容,而不是按字面意義。
我希望這對您有所幫助,即使您已經回答了問題。
或無需轉義雙引號:
$leftMenu = '<div class="leftMenuProductButton">' . $raceramps56["short"] . '</div>';
$raceramps56["short"] = "My Test Product";
$leftMenu = '<div class="leftMenuProductButton">' . $raceramps56["short"] . '</div>';
echo $leftMenu;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.