2012-09-19 19 views
-1

我該如何在PHP代碼的「and」之間插入html。如何在php語音標記之間插入html

我想插入html代碼,它說hello - 但它不會讓我。

$this->setError($postName, ucfirst($postName)." hello."); 
} else if(strlen($postVal) > intval($max)) { 

我想插入此代碼,它說你好。

<div class="alert alert-success"> 
    <button type="button" class="close" data-dismiss="alert">&times;</button> 
      <strong>Thank You!</strong> We hope to get back to you shortly. 
</div> 
+0

對於記錄來說,它是「雙引號」而不是「語音標記」。 – Christian

回答

1
$str = '<div class="alert alert-success"> 
       <button type="button" class="close" data-dismiss="alert">&times;</button> 
       <strong>Thank You!</strong> We hope to get back to you shortly. 
      </div>'; 

    $this->setError($postName, ucfirst($postName).$str); 
} else if(strlen($postVal) > intval($max)) { 
+0

所以我只是在postname後添加$ str?現在就試試 – Dom

+0

謝謝 - 你幫我學了php - 我是新的 – Dom

+0

@Dom我糾正了John的縮進。雖然代碼仍然有效,但正確的縮進是程序員的一個非常重要的屬性。它使代碼易讀並且更易於調試。我正在寫這個,所以你記下它並自己做。從經驗中,我看到很多人都聳聳肩,說:「是的,我會在最後這樣做......」事實從來不是這樣,從一開始就適當地做。它也將免除你的代碼的未來維護者的憤怒;) – Christian

0

你會是HTML代碼,只需添加一個變量,並簡單地拼接,你想讓它。

所以沿着線的東西:

$html = '<div class="alert alert-success"> 
    <button type="button" class="close" data-dismiss="alert">&times;</button> 
    <strong>Thank You!</strong> We hope to get back to you shortly. 
</div>'; 

    $this->setError($postName, ucfirst($postName).$html); 
} else if(strlen($postVal) > intval($max)) { 

希望這有助於。 :) (對不起,如果這屬於一個評論,實際上不能在問題中發表評論。)

+1

我不喜歡這個答案upvoting,但另一方面,我不明白爲什麼它值得downvote?! – Christian

+0

謝謝@Christian!是的,我不知道爲什麼我會得到很多的讚揚,我真的沒有發佈任何值得讚揚的東西。感謝您的支持。 :) – greduan

相關問題