我是新來的PHP。我在我的WordPress網站的functions.php文件中有以下行。我認爲我的格式爲get_the_bag
的方式有問題。有人能讓我知道什麼是錯的嗎?這一行代碼有什麼問題? (PHP內php)
$output .= "<span class='bag-item'>. get_the_bag(); .</span>";
我是新來的PHP。我在我的WordPress網站的functions.php文件中有以下行。我認爲我的格式爲get_the_bag
的方式有問題。有人能讓我知道什麼是錯的嗎?這一行代碼有什麼問題? (PHP內php)
$output .= "<span class='bag-item'>. get_the_bag(); .</span>";
;
)
你想:
$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
包裝那個函數調用)。
從get_the_bag()
後刪除分號和第一跨度之後和在第二位speechmarks:
$output .= "<span class='bag-item'>". get_the_bag() ."</span>";
try this
$output .= "<span class='bag-item'>" . get_the_bag() . "</span>";