用echo輸出html拼接php函數(shù)輸出無法輸出到標簽對
function bloginfo_head(){
if(is_home()){
/*問題點*/
echo '<title>' . blog_title() . '</title>';
}
}
輸出結(jié)果
需要怎么拼接?
2 回答

吃雞游戲
TA貢獻1829條經(jīng)驗 獲得超7個贊
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<?php
$title = "hahaha";
echo "<title>$title</title>";
echo "<title>" . $title . "</title>";
?>
</head>
<body>
</body>
</html>
上面的兩個都可以輸出,你需要定位是不是這一段引起的:
- 是否調(diào)用了bloginfo_head()方法
- is_home()是否是true
- blog_title() 是不是空字符串
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<?php
function bloginfo_head()
{
if (is_home()) {
$titles = blog_title();
echo '<title>' . $titles . '</title>';
}
}
function is_home()
{
return true;
}
function blog_title()
{
return '這是一個title';
}
bloginfo_head();
?>
</head>
<body>
</body>
</html>
不像你說的樣子,你的blog_title()方法是echo,還是return

GCT1015
TA貢獻1827條經(jīng)驗 獲得超4個贊
function bloginfo_head(){
if(is_home()){
$titles = blog_title();
/*問題點*/
echo "<title>$titles</title>";
}
}
- 2 回答
- 0 關(guān)注
- 963 瀏覽
添加回答
舉報
0/150
提交
取消