Jump to content

Should be Simple


ShiVer

Recommended Posts

Alright, I'm making this way to complicated on myself so hopefully someone with a fresh start could help.

Heres the plan:
I have several files in a directory.
I want to open and read the directory to only find text files.
The text files are setup in the following format: [b]picture.jpg|Title of Clip|clip.flv[/b]
"[i]foreach[/i]" text file I want to explode to an array so I can show it like the following:

HTML>>
[code]-------------
|           | Title of clip
|  picture  |
|           |
-------------[/code]

The image and title will be a hyperlink so that when clicked it will open up another text document set by myself and write to it the clip.flv

Note: So basically it's like uploading the information to a database and then using a while loop to pull it out and show all the results. The situation being the way it is I don't have access to a DB so I'm trying to use flatfile.

I know most of you are probably lost now so please ask any questions and I'll do my best to answer! Thanks!

- Ryan
Link to comment
Share on other sites

You could try something like this...
[code]<?php
//Loop through all text files in a directory
foreach(glob("path/to/files/*.txt") as $file) {
    $content = file($file);
    //Loop through each line in the file
    foreach($content as $line) {
        //Seperate the line by the pipe symbol into an array and display
        $temp = explode("|",$line);
        echo "<p>Image: $temp[0]<br/>Title: $temp[1]<br/>Flash: $temp[2]</p>";
    }
}
?>[/code]
Link to comment
Share on other sites

This answer assumes that all the text files are named "something.txt"

[code]<?php
foreach(glob(*.txt) as $textfile) {
    $tmp = file($textfile);
    list($pic, $title, $clip) = explode(trim($tmp[0]));
    list($w, $h, $t, $attr) = getimagesize($filename);
    echo '<img src="' . $pic . '" ' . $attr . '><a href="' . $clip . '">' . $title . '</a><br>';
}
?>[/code]

Ken
Link to comment
Share on other sites

Thank you all, I got SemiApocalyptic's to work but I used kenrbnsn's.

[b]@kenrbnsn[/b]: Ya forgot the seperation parameter in explode. lol

Thanks again to all three of ya. I'll be set for the next time I need to do somethin like this as well!

- Ryan
Link to comment
Share on other sites

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.