2012-03-29 38 views
-2

不確定如何讓該字符串正常工作。讓我的頁面留空。需要字符串中的多個變量

$imagefile = "http://mysite.ca/uploads/pages/large/$flyer['flyer_id']/$page['large_image']"; 
$imagedata = getimagesize($imagefile); 
$imagewidth = $imagedata[0]; 
$imageheight = $imagedata[1]; 

我認爲它與兩個變量混合使用常規文本有關。

+0

輸出示例將 http://mysite.ca/uploads/pages/large/83/best-buy-flyer-mar-23-to-291.jpg – 2012-03-29 06:32:55

回答

4

不要嵌入變量的字符串:

$imagefile = "http://mysite.ca/uploads/pages/large/".$flyer['flyer_id']."/".$page['large_image']; 

{}他們包裹:

$imagefile = "http://mysite.ca/uploads/pages/large/{$flyer['flyer_id']}/{$page['large_image']}"; 

或刪除圍繞陣列關鍵引號(這是完全允許一個雙內引用字符串):

$imagefile = "http://mysite.ca/uploads/pages/large/$flyer[flyer_id]/$page[large_image]"; 
+0

感謝的作品。但是,當我嘗試echo $ imageheight或$ imagewidth時,不會打印任何內容。當我回顯$ imagefile時,我得到了圖像的正確完整路徑。 – 2012-03-29 06:40:24

+0

添加'error_reporting(E_ALL); ini_set('display_errors','on');'查看所有錯誤。也許'url_fopen_wrappers'在您的服務器上被禁用。 – ThiefMaster 2012-03-29 06:42:17

0

我想你需要添加小鬍子括號(so rry無法記住它們實際調用的內容),以使它們可以作爲變量正確讀取。

$imagefile = "http://mysite.ca/uploads/pages/large/{$flyer['flyer_id']}/{$page['large_image']}"; 
相關問題