玉家伙又需要你的帮助,解析阵列到收藏夹评论
以前大家给我介绍了其收藏一些调整后,已经很大。除了使用我的PHP代码,似乎没有一种方法来添加标题的图像。现在我的一个朋友向我介绍使用.txt文件进行数组。现在这一切都很好,但我似乎无法得到我们想要正确读取文件的代码。目前它是随机抽取字母“a”和字母“p”并指定的,我不知道它在哪里得到这个。
现在这里是我想出来的文件的内容的代码。
<?php
// process caption file into named array
//open the file
$myFile = "captions.txt";
$fh = fopen($myFile, 'r') or die("Can't open file");
$theData = explode(fread($fh, filesize($myFile)),"\n");
//close the file
fclose($fh);
//parse line by line until there is no data left.
foreach ($theData as $item => $line) {
$exploded = explode("=", $line);
if (count($exploded) == 2) {
$myFile[$exploded[0]] = $exploded[1];
}
}
?>
然后我使用的代码自动填充我的图片相册反过来激活lighbtox。
<?php
$images = glob('*.{jpg,jpeg,png,gif}', GLOB_BRACE);
foreach ($images as $image) {
if (file_exists("./thumbs/{$image}")){
echo "<a href=\"{$image}\" rel=\"lightbox[gallery]\" title=\"" . $myFile[$image] . "\" style=\"margin-left:25px; margin-right:25px; margin-top:30px; display:inline-block; border:5px solid #fff;\"><img src=\"thumbs/{$image}\" alt=\"{$image}\" /></a>";
}
}
?>
使用此代码生成任何错误,但不正确读取的字幕文件。
我想要做的就是文本文件的安装与文件名分开a =和然后标题。
这里是我的测试页面的链接,如果有人想看一看。
http://outtamymindphoto.myftp.org/images/testalbum/testpage.php
你好,我的朋友又看了看代码,发现他犯了一些错误。他为我重写了它,并且记录了他在做什么,所以我可以从中学习,并与原文进行比较。新代码包含了您建议的所有内容。谢谢 – Steven 2012-08-06 22:00:39
不客气。 – 2012-08-06 22:01:50