2013-10-28 59 views
-2

我已經很長時間了,因爲我對php這個愚蠢的問題感到抱歉。回聲裏面的回聲 - 它的工作?

這是我當前的代碼,我試圖將URL保存爲一個變量,這樣我可以將其插入回聲,但它似乎並不如無工作出現:

<?php ob_start(); 
echo get_post_meta($post->ID, 'oldurl', true); 
$old_url = ob_get_contents(); 
ob_end_clean(); 
?> 

<?php echo do_shortcode('[fbcomments][fbcomments url="$old_url" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?> 

我回應$old_url,可以看到它具有正確的值,但是如何將值插入echo do_shortcodeurl="$old_url"

這不起作用或者:

<?php echo do_shortcode('[fbcomments][fbcomments url="echo $old_url;" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?> 
+0

答案是否定的。 – Kermit

+0

我在所示的代碼中看不到任何意義。如果'get_post_meta'返回一個可以被回顯的值 - 那麼爲什麼_would_你會回顯它,並使用輸出緩衝來捕獲那個輸出,而不是直接用'$ foo = get_post_meta(...)'...來實現呢? – CBroe

+0

只要你可以使用'url =「$ old_url」''''''''''''''''''''''''''''' num =「3」countmsg =「精彩評論!」]');' – Roopendra

回答

1

你需要切換左右的報價。單引號按原樣打印所有內容。雙引號將處理這些變量。另外,回聲中不需要回聲。

<?php echo do_shortcode("[fbcomments][fbcomments url='$old_url' width='375' count='off' num='3' countmsg='wonderful comments!']"); ?>  

另一種方式來做到這一點無需切換的報價是打出來的語句:

<?php echo do_shortcode('[fbcomments][fbcomments url="'.$old_url.'" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?> 
1

的變量不是在單引號替換......

<?php echo do_shortcode('[fbcomments][fbcomments url="' . $old_url . '" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?> 
0

單打報價不允許變量解析。
例如:

$var = 'Hello'; 
echo 'The content of my var is : $var'; 
// Will output : "The content of my var is : $var" 
echo "The content of my var is : $var"; 
// Will output : "The content of my var is : Hello" 

所以,你必須使用雙引號或使用連接操作符:.