2011-12-07 44 views
1

我有一個tpl.php文件此代碼爲什麼我在這裏得到未定義的變量錯誤?

<?php foreach ($images as $image): ?> 
    <?php print $image ."\n"; ?> 
<?php endforeach; ?> 

我已中的預處理功能

function preprocess(&$vars) { 
    // Initialize our $images array. 
    $vars['images'] = array(); 

    foreach ($vars['rows'] as $item) { 
    if (preg_match('@(<a.*?img.*?</a>)@i', $item, $matches)) { 
     $image = $matches[1]; 
    } 
    elseif (preg_match('@(<\s*img\s+[^>]*>)@i', $item, $matches)) { 
     $image = $matches[1]; 
    } 
    else {$images = NULL;} 
    // Add the image to our image array 
    $vars['images'][] = $image; 
    } 

未定義可變以下:在此行中的預處理功能圖像

$vars['images'][] = $image; 

回答

5

Typo。

$images = NULL; 

應該

$image = NULL; 
+0

我的錯誤我編輯了上面的代碼。我沒有在原始文章中包含圖片聲明。 – dimmech

1

else:你有複數$圖像而不是$圖像

+0

謝謝,這是它! – dimmech

相關問題