【发布时间】:2015-06-01 11:13:17
【问题描述】:
我有一个来自 UberGallery 的 UberGallery.php,我正在使用它。
对于每个图像弹出窗口,图像底部都会显示图像名称(例如 4488826 6f061c99ec b d),该图像取自 UberGallery.php
// Loop through array and add additional info
foreach ($dirArray as $key => $image) {
// Get files relative path
$relativePath = $this->_rImgDir . '/' . $key;
$galleryArray['images'][htmlentities(pathinfo($image['real_path'], PATHINFO_BASENAME))] = array(
'file_title' => str_replace('_', ' ', pathinfo($image['real_path'], PATHINFO_FILENAME)),
'file_path' => htmlentities($relativePath),
'thumb_path' => $this->_createThumbnail($image['real_path'])
);
}
上面代码中的 file_title 正在影响要更改的标题。图片在 defaultGallery.php 中显示如下
<?php if (!empty($images) && $stats['total_images'] > 0): ?>
<ul id="galleryList" class="clearfix">
<?php foreach ($images as $image): ?>
<li><a href="<?php echo html_entity_decode($image['file_path']); ?>" title="<?php echo $image['file_title']; ?>" rel="<?php echo $relText; ?>"><img src="<?php echo $image['thumb_path']; ?>" alt="<?php echo $image['file_title']; ?>"/></a></li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p>No images found.</p>
<?php endif; ?>
现在我想在每个图像弹出窗口的图像底部显示图像名称 (4488826 6f061c99ec b d) 和电子邮件地址 (aaa@gmail.com)。
如果我在上面的 file_title's str_replace 函数中更改以从 csv 文件中获取电子邮件地址,则不会出现任何内容。
gallery.csv 有两个字段,如 4488826 6f061c99ec b d aaa@gmail.com。我想将这两个值传递给 file_title 以便它们出现在图像弹出窗口中。
$file_handle = fopen("gallery.csv", "r");
while (!feof($file_handle)) {
$lines_of_text[] = fgetcsv($file_handle, 1024);
}
fclose($file_handle);
// Loop through array and add additional info
foreach ($dirArray as $key => $image) {
// Get files relative path
$relativePath = $this->_rImgDir . '/' . $key;
$galleryArray['images'][htmlentities(pathinfo($image['real_path'], PATHINFO_BASENAME))] = array(
'file_title' => str_replace('_', $lines_of_text[1], pathinfo($image['real_path'], PATHINFO_FILENAME)),
'file_path' => htmlentities($relativePath),
'thumb_path' => $this->_createThumbnail($image['real_path'])
);
}
我应该如何将姓名和电子邮件传递到上面的 file_title 以获得所需的结果? 或者有没有其他方法可以做到这一点?
请帮我找出解决办法。
【问题讨论】:
标签: php arrays csv associative-array