genertaing txt using php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aarya
    New Member
    • Sep 2005
    • 5

    #1

    genertaing txt using php

    i have a problem in generating txt file from php. my prblem is After I add a news item etc. the script that updates the database would geneterate a text file. Then in my code instead of my 'include file show_news.php3' command, I would do a a include news.html that would be a pre-built html page. I think this would make the pages load faster. vs. making a bunch of mysql call each time a page is called. will u please help me
  • rohypnol
    New Member
    • Dec 2007
    • 54

    #2
    Originally posted by aarya
    the script that updates the database would geneterate a text file.
    If you have something like:

    ** INDEX.PHP
    [PHP]Welcome to my page! Here is the news:
    <?php
    ..read from database..
    foreach($db_dat a as $db_element)
    echo $db_element."\r \n";
    ?>[/PHP]

    Then you might want to try:

    ** GEN_NEWS.PHP
    [PHP]<?php
    ..read from database..
    $output = "";
    foreach($db_dat a as $db_element)
    $output .= $db_element."\r \n";
    file_put_conten ts("news.html" , $output);
    ?>[/PHP]

    Be careful: when outputting unknown text (such as this html file) use the readfile() function! If you use include(), then php tags will be processed and in case one of them exists, your script will be messed up and it is a major security flaw if anyone else can control the contents of that file (they will be able to make your server execute anything!). In your case there is no need for php tags to be processed and you want to avoid any problems that might pop up.
    So your main page should contain something like this:

    ** INDEX.PHP
    [PHP]Welcome to my page! Here is the news:
    <?php
    readfile("news. html");
    ?>[/PHP]

    and open the gen_news.php file whenever you want to recreate the output file.

    But honestly, I don't see why querying the server would be such a problem unless it's a very slow computer, or the connection between the php server and news database server is slow, or if you have something like 100.000 items of news and you want to filter them... otherwise, you should do some benchmarking because I doubt doing queries to get the latest news from the db is such a big problem.

    Good luck,
    Tom

    Comment

    Working...