2011-07-19 25 views
0

我是新來的PHP。我在我的WordPress網站的functions.php文件中有以下行。我認爲我的格式爲get_the_bag的方式有問題。有人能讓我知道什麼是錯的嗎?這一行代碼有什麼問題? (PHP內php)

$output .= "<span class='bag-item'>. get_the_bag(); .</span>";

回答

2
  1. 你掉了各種級聯的東西,一個函數調用到的中間字符串
  2. 您在函數調用
  3. 之後終止了聲明(與 ;

你想:

$output .= sprintf("<span class='bag-item'>%s</span>", get_the_bag()); 

或者

$output .= "<span class='bag-item'>" . get_the_bag() . "</span>"; 

(這兩個假設get_the_bag返回一個HTML安全的字符串。如果不是,你需要用htmlspecialchars包裝那個函數調用)。

3

get_the_bag()後刪除分號和第一跨度之後和在第二位speechmarks:

$output .= "<span class='bag-item'>". get_the_bag() ."</span>"; 
0
try this 

$output .= "<span class='bag-item'>" . get_the_bag() . "</span>";