Help with dynamically changing captions via img title tag

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • letshin
    New Member
    • Mar 2008
    • 4

    Help with dynamically changing captions via img title tag

    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
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    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?

    Comment

    • letshin
      New Member
      • Mar 2008
      • 4

      #3
      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("$dirnameh ttp/$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=="fi lename_from_tex t_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.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Are you able to use a mysql database?

        IT would make things a hell of alot easier.

        Comment

        • letshin
          New Member
          • Mar 2008
          • 4

          #5
          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?

          Comment

          • letshin
            New Member
            • Mar 2008
            • 4

            #6
            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

            Code:
            $filetext = "text.txt"; // File which holds all data
            
            	$arrFp = file( $filetext ); // Open the data file as an array
            	$numLines = count( $arrFp ); // Count the elements in the array
            
                for($j=0; $j<=$numLines; $j++) // Loop through the lines of the text file
                {
                    if(strstr($arrWords[$i],':') == $filename){ 
            		strstr($arrWords[$i],':',true) = $title
            		}            //Line 335 is here.
                }

            Comment

            Working...