[英]php echo inside $output
我正在嘗試從頁面中獲取特定頁面內容,我需要插入此 php 代碼:
我試過這個:
$output .= <<<HTML
</div>
</div>
<div id="hometabs">
echo getPageContent(8);
</div>
<div class="clear"></div>
</div>
<div class="bottom_shadow"></div>
</div>
HTML;
但它不起作用..我什至試過:
getPageContent(8);
echo getPageContent(8)
<?php echo getPageContent(8);?>
還是沒有
注意:我已經有了 getPageContent 的代碼,我只是不知道為什么在我的瀏覽器上查看時,此代碼: echo getPageContent(8) 顯示而不是執行它。
您使用的語法在 PHP 中稱為Heredoc 。 這是一種構建字符串並將其放入變量的特殊方法,但它允許您使用換行符和引號以及其他很酷的東西(例如在字符串中使用 php 變量)。
不幸的是,除非您對代碼進行一些特殊和創造性的語法更改,否則您無法在 heredoc 中執行函數。 這是另一個類似於您所面臨的問題: Calling PHP functions within HEREDOC strings 。
如果我這樣做,我可能會像這樣更改語法(看看這是否適合您):
$the_content = getPageContent(8);
$output .= <<<HTML
</div>
</div>
<div id="hometabs">
$the_content
</div>
<div class="clear"></div>
</div>
<div class="bottom_shadow"></div>
</div>
HTML;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.