2011-12-07 39 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

相关问题