SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Enthusiast XploreR's Avatar
    Join Date
    May 2001
    Location
    Singapore
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi ,

    i have a txt file that contains some data like:


    <tr><td><font face="arial" size="3">1</font></td><td><font face="arial" size="3">NTSC Mode</font></td><td><font face="arial" size="3"> 35AC1D55CEED</font></td></tr>

    <tr><td><font face="arial" size="3">2</font></td><td><font face="arial" size="3">Y-Fix</font></td><td><font face="arial" size="3"> 8DAD0F83CECD</font></td></tr>


    I would like to know know to output the contents exactly in PHP.

    What i have done is to specify the path of the txt file


    $path = "/home/xiccc/www/codes/game.txt";

    readfile ($path);


    Any comments would be helpful. I would like to know if what i have done is correct as i got the output correctly, but it didn't work with PHPLib Template. Thus, I would also like to know how to have the data in the txt file to be used with PHPLib Template. How do i passed the data to a variable? (possible?)

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $filedescriptor fopen("filename.txt","r"); // or "rb" if a binary file on a Windows server
    $data fread($filedescriptorfilesize("filename.txt"));
    fclose($filedescriptor);

    echo(
    $data); 
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    SitePoint Enthusiast XploreR's Avatar
    Join Date
    May 2001
    Location
    Singapore
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    With PhpLib Template

    Hi kevinyank,

    well, a bit surprsied to see ur reply. LOL. Well, like to say :"Your articles were great and were of great help to me!"

    Anyway, anyone can tell me how to get it to work with PHPLib templates?

    I tried doing this but it dosen't work


    $filedescriptor = fopen("$path","r"); // or "rb" if a binary file on a Windows server
    $data = fread($filedescriptor, filesize("$path"));
    fclose($filedescriptor);

    $temp = "$data";
    $t->set_var('codes', $temp);
    $t->parse('CBlock', 'CodesBlock', true);

  4. #4
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Looks OK, although I am not familiar with PHPLib templates. What are you seeing?
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  5. #5
    SitePoint Enthusiast XploreR's Avatar
    Join Date
    May 2001
    Location
    Singapore
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I only saw the contents/ data of the txt.file.

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is it you are trying to do with PHPLIB just put the contents of the text file in to the {codes} portion of your template? Or is there something we are missing here? It appears you are trying to use a block in the template, if this is the case please let us know. Right now what you are doing is taking the whole text file and putting it in a variable named $data then assigning $data to $temp then putting $temp into the template. Where is your code to set up the template? If you show us this and explain exactly what you want to do with the text file we can be of more assistance.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    SitePoint Enthusiast XploreR's Avatar
    Join Date
    May 2001
    Location
    Singapore
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi freddydoesphp,

    yes, i want the contents of the txt.file to be displayed on a template where the {codes} are but i cannot seemed to get the template to work. The results are the contents of the file only.

    This is my template:


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <html>
    <head>
    <title>{title}</title>
    </head>

    <body>

    <center>
    <table width="500" border="0">
    <!-- BEGIN CodesBlock -->
    {codes}
    <!-- END CodesBlock -->
    </table>
    </center>

    </body>
    </html>


  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your template looks okay, I think you have a problem in your php code, especially if what you posted earlier is what you are using, could you post the php code so we can look at it?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    SitePoint Enthusiast XploreR's Avatar
    Join Date
    May 2001
    Location
    Singapore
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's My code. Frankly, i've looked at it for many times and i found no mistakes myself. Please Help


    <?

    include("/home/xiccc/www/templates/template.inc");
    $t = new Template("/home/xiccc/www/templates/", "keep");

    $game = 'Dynasty Warriors';
    $platform = 'Playstation';

    $t->set_file('codes', 'codes.phtml');
    $t->set_block('codes', 'CodesBlock', 'CBlock');
    $t->set_var('title', "$game - $platform Xploder Codes (XploderCodes.Com)");
    $t->set_var('platform', "$platform");
    $t->set_var('gametitle', "$game");


    $path = "/home/xiccc/www/codes/dynastywarriors.txt";

    $filedescriptor = fopen("$path","r"); // or "rb" if a binary file on a Windows server
    $data = fread($filedescriptor, filesize("$path"));
    fclose($filedescriptor);

    $temp = "$data";
    $t->set_var('codes', $temp);
    $t->parse('CBlock', 'CodesBlock', true);


    $t->pparse('Output', 'codes');

    ?>

  10. #10
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OKay so, when you use the fopen method you showed below you are basically grabbing every line from the text fiel and putting into one variable in this case $data. Now you are using a block in the template which is normally reserved for repeating chunks of code. If this is what you intended you probably should have used file() instead of fopen() and fread();

    So for your case I would have done this. BTW the reason yours didn't work is because the variable conflict of your template handle "codes" and your block var "codes", notice how I changed your template handle to "code" and now it should work fine.


    <?


    include("/home/xiccc/www/templates/template.inc");
    $t = new Template("/home/xiccc/www/templates/", "keep");

    $game = 'Dynasty Warriors';
    $platform = 'Playstation';

    $t->set_file("code", './codes.phtml');
    $t->set_block("code", 'CodesBlock', 'CBlock');
    $t->set_var(array("title" => "$game - $platform Xploder Codes (XploderCodes.Com)",
    "platform" => $platform,
    "gametitle" => $game
    ));


    $path = "/home/xiccc/www/codes/dynastywarriors.txt";

    $data = file($path); // grab each line from file and put in an array
    foreach($data as $key => $val) { //Loop through the array and assign each line to the block CodesBlock
    $t->set_var('codes', $val);
    $t->parse('CBlock', 'CodesBlock', true);
    }

    $t->pparse('Output', 'code');

    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  11. #11
    SitePoint Enthusiast XploreR's Avatar
    Join Date
    May 2001
    Location
    Singapore
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    freddydoesphp,

    tested ur code and it works. thanks for the help and information!

  12. #12
    SitePoint Enthusiast XploreR's Avatar
    Join Date
    May 2001
    Location
    Singapore
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Comments Please :)

    ok, i now need some comments regarding this. As i have stated, the contents of my txt. file are like this:


    <tr><td><font face="arial" size="3">1</font></td><td><font face="arial" size="3">NTSC Mode</font></td><td><font face="arial" size="3"> 35AC1D55CEED</font></td></tr>


    First, i run a game codes website. I feel kinda troublesome by the fact that i still need to use html coding in the txt file. I would like some feedback from any professional web developer or anybody who knows a way to help me find a way to rid the html coding in the txt file via PHPLib or any other method. But there's one major problem:

    Taking the coding above, as there are different datas for my case - one column holds the code number, one the code description (for example, NTSC Mode)and the other is the code value (35AC1D55CEED). Some games have codes upto thousands of them and i wouldn't want to write all those html stuff (repeat).

    I've thought of entering the code datas via mysql but it would take time to enter all of them tho.

    Any feedback welcome on an ideal solution (PHP/Mysql/others)!!
    Last edited by XploreR; May 20, 2001 at 11:19.


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
  •