Connecting Tech Pros Worldwide Forums | Help | Site Map

Help with dynamically changing captions via img title tag

Newbie
 
Join Date: Mar 2008
Posts: 4
#1: Mar 11 '08
Hello!

I have been trying to write a script that changes the title tag of my images. This is because I'm using a script to generate an image gallery, which I linked to a lightbox. I need to put a caption to the images cause well, I think the visitors would like to know what they're looking at :p/ Thing is, I am absolutely clueless now. I have a vague idea though, which is basically to have a text file containing lines with things like,

img1.jpg, This is your caption
and so on

Which I'd access using fopen and fget, split it using explode, loop the lines into an array, match it to $filename using an if statement and change the $title tag accordingly. My previous experience of PHP is from copying and pasting scripts and modifying them. XD

I'd really, really appreciate some help here. Thanks! :p

dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,095
#2: Mar 11 '08

re: Help with dynamically changing captions via img title tag


So how are you doing it now? If you use lightbox, can you post the relative code?

you should be able to read their PHP code unless its obfuscated (scrambled) in that case, Good luck.

Those images and captions have to be stored somewhere, a file and explode is good if the file is not large. otherwise create a database and consider pagation methods.

Is your question how to modify lightbox photo gallery to also store title of image?
Newbie
 
Join Date: Mar 2008
Posts: 4
#3: Mar 11 '08

re: Help with dynamically changing captions via img title tag


Edit: Posted code doesn't show itself so I removed it. Think its too long. But if you google galerie.php, you should be able to find the script. Its distributed under GNU public licence.

At line 330,
else echo('<a href="' . html("$dirnamehttp/$filename") . '" rel="ibox');

I think I should add a title="$title"
where $title is gotten from a delimited text file which consists of the filename and the title tag. Since the original script already has a $filename variable, I thought of doing something like
if ($filename=="filename_from_text_file")
$title = "caption from text file"

But, like i said I can't program at all / very well in php, so I have no idea what to do..Haha. I only have a general sort of idea.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#4: Mar 11 '08

re: Help with dynamically changing captions via img title tag


Are you able to use a mysql database?

IT would make things a hell of alot easier.
Newbie
 
Join Date: Mar 2008
Posts: 4
#5: Mar 12 '08

re: Help with dynamically changing captions via img title tag


Quote:

Originally Posted by markusn00b

Are you able to use a mysql database?

IT would make things a hell of alot easier.

Yup. I am able to use a database. But I'm trying not to make the things too complicated since the site I'm making is a volunteer job. Once I'm done, it'll be up to my bosses to update the site. As it stands now, I have a few folders of different types of images. Each folder has a set of css, javascript and the gallery generation php script. I thought that I might me able to modify the existing script so that all I need to do is to add a text file containing filenames and scripts to each folder.

Is that possible?
Newbie
 
Join Date: Mar 2008
Posts: 4
#6: Mar 12 '08

re: Help with dynamically changing captions via img title tag


Hey guys. I finally came up with something but I get this fatal error message. Sigh, programming is driving me nuts. Any idea how I can fix it?

Fatal error: Can't use function return value in write context in /Users/leongz/Sites/images/web pics/hanem/gall.php on line 335

Expand|Select|Wrap|Line Numbers
  1. $filetext = "text.txt"; // File which holds all data
  2.  
  3.     $arrFp = file( $filetext ); // Open the data file as an array
  4.     $numLines = count( $arrFp ); // Count the elements in the array
  5.  
  6.     for($j=0; $j<=$numLines; $j++) // Loop through the lines of the text file
  7.     {
  8.         if(strstr($arrWords[$i],':') == $filename){ 
  9.         strstr($arrWords[$i],':',true) = $title
  10.         }            //Line 335 is here.
  11.     }
  12.  
Reply