php
  • concatenation
  • 2017-04-24 96 views 0 likes 
    0

    我有一個php noob時刻,即時尋找一個更小的更緊湊的解決方案來連接「$ content」變量,它被作爲外部「佈局中的主要內容.php「文件。php變量賦值來顯示html和php變量

    <?php 
    
    require_once("Controller/comment_control.php"); 
    $comment = new COMMENT(); 
    
    $title = "Customer Reviews"; 
    $content = '<div class="comment_box">' ; 
    $content .= $comment->getComments(); 
    $content .= '</div>'; 
    

    任何幫助凝結這個醜陋的混亂是讚賞。

    +0

    如果您'正在尋找關於編碼風格的建議,發佈的正確位置是CodeReview.stackexchange.com 。 SO是爲了幫助解決代碼中的問題。 – Barmar

    +0

    筆記,謝謝。 – rsahs

    回答

    0

    想通了,包含在括號中的PHP調用獲得最後的結果我想

    $content = '<div class="comment_box">' . ($comment->getComments()) . '</div>'; 
    
    +0

    您的原始代碼應該完全一樣。如果你看到源代碼,這是一個不同的問題。 – Barmar

    0

    用sprintf()

    SPRINTF

    例子:

    $content = sprintf('<div class="comment_box">%s</div>', $comment->getComments()); 
    
    +0

    爲什麼這個工作和他原來的代碼有什麼不同? – Barmar

    +0

    因爲他問:我正在尋找一個更小巧的解決方案來連接「$ content」變量 –

    +0

    我以爲他的問題是他在網頁上看到源代碼。 – Barmar

    相關問題