[英]Why am I getting undefined variable error here?
我在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;
错别字。
$images = NULL;
应该
$image = NULL;
else
:您有多个$ images而不是$ image 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.