Results 1 to 6 of 6

Thread: Echo txt files with delimiter

  1. #1
    Join Date
    May 2010
    Posts
    30
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Echo txt files with delimiter

    Hello Great Coders,

    I read about this tutorial but having troubles implementing it...
    I want this code:
    <div class="pager hidepiece">
    <div class="img rand" >
    <a href="/video/(channel).php?t=(title)&id=(video id)"><img src="(image)" alt="(title)"></a>
    <div class="desc truncate" >(title)</div>
    </div>
    </div>
    ...to be echoed as the container of my contents from a .txt file.


    My contents are formatted like this:
    channel|title|video|image
    sample contents: archives.txt
    teenamite|title1|video1|image1
    teenamite|title2|video2|image2
    teenamite|title3|video3|image3
    teenamite|title4|video4|image4
    teenamite|title5|video5|image5
    etc...
    Hope you can help me with this...
    Thank you in advance and more power!

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    PHP Code:
    <?php
    $input 
    file('path/to/my/file.txt');
    foreach (
    $input as $line) {
         
    $line explode('|',$line);
         
    ?>
         <div class="pager hidepiece">
         <div class="img rand" >
         <a href="/video/<?php echo $line[0]; ?>.php?t=<?php echo urlencode($line[2]); ?>&id=<?php echo urlencode($line[1]); ?>"><img src="<?php echo $line[3]; ?>" alt="<?php echo $line[1]; ?>"></a>
         <div class="desc truncate" ><?php echo $line[1]; ?></div>
         </div>
         </div> 
         <?php
    }
    ?>
    In the future it is better if you can post your existing code for us to work with.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. The Following User Says Thank You to djr33 For This Useful Post:

    william james (01-08-2011)

  4. #3
    Join Date
    May 2010
    Posts
    30
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33 View Post
    PHP Code:
    <?php
    $input 
    file('path/to/my/file.txt');
    foreach (
    $input as $line) {
         
    $line explode('|',$line);
         
    ?>
         <div class="pager hidepiece">
         <div class="img rand" >
         <a href="/video/<?php echo $line[0]; ?>.php?t=<?php echo urlencode($line[2]); ?>&id=<?php echo urlencode($line[1]); ?>"><img src="<?php echo $line[3]; ?>" alt="<?php echo $line[1]; ?>"></a>
         <div class="desc truncate" ><?php echo $line[1]; ?></div>
         </div>
         </div> 
         <?php
    }
    ?>
    In the future it is better if you can post your existing code for us to work with.
    Your code works perfect Sir! Thanks a million! No need to put the complete div codes per line inside a txt file!

    Sad to say I dont know much about php... I am more into css.

    Ive just found a .flv video sponsors and had an idea to create a site where in the main goal is on how to add videos with few clicks.

    I surf around the web and collected pre coded php which I feel my project needs (copy/paste ). I am 90% done! This would not be possible without the help of great coders here like you!

    With the tools I collected, I can now add 1000 vids in just 1 min!

    I have plenty of friends online who are willing to buy my script and I will be glad to donate here the moment I generate sales

    It's an adult site

    I just launched it yesterday though the codings are not yet fully completed.

    I have more follow up questions if it is not yet too much
    Ill just gather my thoughts....
    Last edited by djr33; 01-08-2011 at 06:45 AM. Reason: link to adult site removed

  5. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I'm glad it worked.

    Due to the nature of that link, I've removed it from your post. We can still help with questions, but since this is a forum for "all audiences", it's best to not link directly to certain content.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. The Following User Says Thank You to djr33 For This Useful Post:

    william james (01-08-2011)

  7. #5
    Join Date
    May 2010
    Posts
    30
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    No problem there Sir!

    This is the final code I'm using, thanks again!
    <?php
    $input = file('archives/teenamite.txt');
    foreach ($input as $line) {
    $line = explode('|',$line);
    ?>
    <div class="pager hidepiece">
    <div class="img rand" >
    <a href="/video/<?php echo $line[0]; ?>.php?t=<?php echo urlencode($line[1]); ?>&id=<?php echo urlencode($line[2]); ?>"><img src="<?php echo $line[3]; ?>" alt="<?php echo $line[1]; ?>"></a>
    <div class="desc truncate" ><?php echo $line[1]; ?></div>
    </div>
    </div>
    <?php
    }
    ?>

    Is it also possible if the echoed lines are came from a certain folder, and not directly from a txt file? I have a folder named "archives" where my .txt files located.

    And how can I combine the features of the following codes provided by Nile(thanks Nile!):
    this code shows the first 4 lines of each txt file from my directory "archives". The first to go on top is the latest updated txt file.
    <?php
    $dir = "archives/"; // the directory name
    $glob = glob($dir."/*.*"); // get all the files with a 'name.extension' name
    $files = array_combine($glob, array_map("file", $glob));
    array_multisort(
    array_map( 'filemtime', $glob ),
    SORT_NUMERIC,
    SORT_DESC,
    $files
    );

    foreach($files as $key=>$value){
    echo "".(implode(array_slice($value, 0, 4)))."";
    }
    ?>


    Hope I am not asking too much of your time... but you can take your time and I am willing to wait
    Thank you in advance!
    Last edited by william james; 01-08-2011 at 07:01 AM.

  8. #6
    Join Date
    May 2010
    Posts
    30
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    After a week of headaches for trying to combine all the codes to have the outcome I want , I finally able to make it work. Thanks for the contributors

    The function of this code is to read a delimited file per line with a pagination(sample post format on the first post).


    <?php
    $input = file($_SERVER['DOCUMENT_ROOT'] . '/archive/18stream.txt'); # This is your text file.
    $items = array();
    foreach ($input as $line) {
    $line = explode('|',$line);
    $items[] = '<div class="pager hidepiece">
    <div class="img rand" >
    <a href="/video/'.$line[0].'.php?t='.urlencode($line[1]).'&id='.urlencode($line[2]).'">
    <img src='.$line[3].' alt='.$line[1].'></a>
    <div class="desc truncate" >'.$line[1].'</div>
    </div>
    </div>';

    }
    $thispage = $PHP_SELF ;
    $num = count($items); // number of items in list
    $per_page = 20; // Number of items to show per page
    $showeachside = 5; // Number of items to show either side of selected page

    $start = $_GET['start'];

    if(empty($start))
    $start=0; // Current start position


    $max_pages = ceil($num / $per_page); // Number of pages
    $cur = ceil($start / $per_page)+1; // Current page number
    ?>

    <?php
    for($x=$start;$x<min($num,($start+$per_page));$x++){
    ?>
    <?php echo $items[$x];?>
    <?php
    }
    ?>
    <?php include '../../wj-content/main.php'; ?>
    <center>

    <table border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td align="center" valign="middle" bgcolor="#EAEAEA">
    <?php
    if(($start-$per_page) >= 0)
    {
    $next = $start-$per_page;
    ?>
    <a href="<?php echo ("$thispage?start=0");?>">First</a>
    |
    <a href="<?php echo ("$thispage".($next>0?("?start=").$next:"?start=0"));?>">< Prev </a>
    <?php
    }
    ?>
    </td>
    <td align="center" valign="middle" class="selected">
    <?php
    $eitherside = ($showeachside * $per_page);
    if($start+1 > $eitherside) echo (" ... ");
    $pg=1;
    if($num>$per_page){
    for($y=0;$y<$num;$y+=$per_page)
    {
    $class=($y==$start)?"pageselected":"";
    if(($y > ($start - $eitherside)) && ($y < ($start + $eitherside)))
    {
    ?>
    &nbsp;<a class="<?php echo ($class);?>" href="<?php echo ("$thispage".($y>0?("?start=").$y:"?start=0"));?>"><?php echo $pg;?></a>&nbsp;
    <?php
    }
    $pg++;
    }
    }
    if(($start+$eitherside)<$num) echo (" ... ");
    ?>
    </td>
    <td align="center" valign="middle" bgcolor="#EAEAEA">
    <?php
    if($start+$per_page<$num)
    {
    ?>
    <a href="<?php echo ("$thispage?start=".max(0,$start+$per_page));?>">Next ></a>
    |
    <a href="<?php echo "$thispage?start=".($num-$per_page);?>">Last</a>
    </center>
    <?php
    }
    ?>
    </td>
    </tr>
    <tr><td colspan="3" align="center" valign="middle">&nbsp;</td></tr>
    <tr>
    <td colspan="3" align="center" valign="middle" class="selected">

    Page <?php echo ($cur);?> of <?php echo ($max_pages);?><br>
    ( <?php echo ($num);?> videos )
    </td>
    </tr>
    </table>
    <style type="text/css">
    <!--
    .pageselected {
    color: #FF0000;
    font-weight: bold;
    }
    -->
    </style>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •