Jump to content

Recommended Posts

Hi there,

I'm setting up an online portfolio and would like to know what the best way to pull up image descriptions would be. I've seen it done before by setting up a text file like this:

image1.jpg; information about this one
image2.jpg; information about the second one.

then when you load image1.jpg onto the page, you also pull up "information about this one" into the page.

Right now I just have a navigation set up where the link is to index.php?id=imagename

and then I load the appropriate image like so:

[code]$first = array('home','about','contact', 'work');

if (in_array($_GET['id'], $first)) {
          print '<img src="http://' . $_SERVER['HTTP_HOST'] . '/images/' . $_GET['id'] . '.jpg" alt="title" />';[/code]

I'm not even sure what the process would be called so I haven't really been able to do research on it.

I know I could set up something using line numbers and call the images by numbers that calls up the appropriate line number - but I'd prefer to have it know which line to pull based on the variable $id.
Link to comment
https://forums.phpfreaks.com/topic/7654-extracting-info-from-a-text-file/
Share on other sites

You can use explode() 2 times... But I would rather create a multidimensional array:

[code]
$data = array (
   '0' => array (
      'img'   => 'image1.jpg';
      'descr' => 'information about this one'
    ),

   '1' => array (
      'img'   => 'image2.jpg';
      'descr' => 'information about the second one.'
    ),
);[/code]

serialize() it and store in a txt. It's more accurate.
I am pretty new at php so I think I need a little bit more information - can anyone either direct me to a tutorial or a script that I could customize?

[!--quoteo(post=365753:date=Apr 17 2006, 07:38 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Apr 17 2006, 07:38 PM) [snapback]365753[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You can use explode() 2 times... But I would rather create a multidimensional array:

[code]
$data = array (
   '0' => array (
      'img'   => 'image1.jpg';
      'descr' => 'information about this one'
    ),

   '1' => array (
      'img'   => 'image2.jpg';
      'descr' => 'information about the second one.'
    ),
);[/code]

serialize() it and store in a txt. It's more accurate.
[/quote]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.