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
https://forums.phpfreaks.com/topic/8633-should-be-simple/
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
https://forums.phpfreaks.com/topic/8633-should-be-simple/#findComment-31689
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
https://forums.phpfreaks.com/topic/8633-should-be-simple/#findComment-31695
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.