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

I think the reason why people are not giving you answers is that it's not clear what your question is. We understand what you want to do, but we don't understand what you are having problems with.

ok i dont know how to do dynamic sites to static sites.
for example i have a real estate sites. the vistitors useses search engine to select resedential sites, he will get set of search list loction,type of land ext .and if person want to know details of that apartment he will click details.
this directs to details?listingid=26.php.
but i want details/26.html. i want in html but not php. i hope u have understood my problem

it can be like this

i want in html but not php. i hope u have understood my problem

Once again. I understand what you are wanting to do, didn't ask any questions. I have actually built a site exactly like this many times (using Perl and MySQL) but didn't redirect to static pages. Redirecting to an html file rather than a php script isn't hard, but I think you are having more problems than just figuring out the redirect. Also, realize that the pages on this forum are not static files; rather, they are most likely html files with embedded PHP that the server parses before returning the file.

Ask questions. Seriously, we don't know what to help you with if we don't know what exactly it is that you don't know how to do.

If you don't know anything about how to make any parts of this program, then you are asking for a lot. I don't think anyone will design the entire project for you and then send you the source code.

If you are just hung up on some specifics, ask specific questions, such as: "How can I redirect out of a PHP script to another file on the site?"

aarya,

I would recommend that you purchase one of the following:

Professional LAMP

Beginning PHP, Apache, MySQL, Web Development

Core PHP Programming: Using PHP to Build Dynamic Web Sites

You seem to have quite a few questions, and this is a great place to start. However, you may want to take a more structured approach with this. That’s not meant to be offensive. It's just that one or more of these books may help bring you the structure you need as a novice, in this area, in a timely manner. You may find forums like this one more useful (a question here a question there that pops up, while you understand the underlying structure) after reading one of those books.

Hi aarya, :cheesy:

The question really is why you want to convert the php pages to static html files, and if it is necessary.

1) URL rewriting: The link you posted, though with an html extension, may actually be parsed by php. If this is the case, that means they are more concerned about Search Engine Friendly (SEF) urls than anything else.

2) PHP Cache: On the other hand they may very well be static html pages. If they are, then they may also be concerned about their server processing, and faster generation of the html page. (php will be slower to generate an html page).

In the case of this forum, (the link you posted above), it is most likely a SEF addon for VBulletin (this forum software) such as found here: http://www.vbulletin.org/forum/showthread.php?t=63314

If you're websites pages are very dynamic, like the real estate search listings page, you would probably want to use url rewriting (1).
Im not an expert, so I only know of the Apache Server methods of doing this.

You can rewrite the urls using mod_rewrite. Which is an apache module.
This is quite long to discuss here, but you can find alot of resources on the web.
Such as: http://www.sitepoint.com/article/search-engine-friendly-urls

If your php page content does not change frequently, but you have alot of hits, and your server is slowing down, you can use a cache system (2).
A chache system, simple creates static html pages out of the php pages you have (but is more complicated then that).
Its discussed here: http://www.zend.com/zend/art/scriptcaching.php

What you can do is search the web for ready made open source scripts that do the job. They take care of a lot of problems that arise when you want to use these methods. (and automate alot of things, like changing all your links to point to the static files).

If you just want to know how to create an static html file from php, and are not concerned about the implementation. Its really simple:

// creates a local version of any url contents as html files
function cache_url($url, $cache_name, $cache_path = 'cache/') {

        // this is simple the path to store the html file
        $cache_abs_path = $cache_path.$cache_name;
        
        // this opens an http connection to the url of your webpage
        // search fopen at php.net
        // you must supply a http path to this, so that we use the http wrapper and return only html
        if (!$file = @fopen($url, 'r')) {
            echo ('could not open the url: '.$url);
            return false;
        }
       
        // this opens a file pointer to the html file you are saving too
        // if the file doesnt exist, then it will attempt to create a new one
        // you need the directory to have write permissions for the script
        // chmod 777  (this can be done via ftp, or a web control panel, or php)
        if (!$cache_file = @fopen($cache_abs_path, 'w+')) {
            echo ('could not open the cache: '.$cache_abs_path.' for writing.');
            return false;
        }

        // here we read the contents of the webpage
        while($read = fread($file, '2082')) {

            $content .= $read;
            
           // we write the content of our webpage to the html file
            if (!@fwrite($cache_file, $read)) {
            echo ('error writing to cache: '.$cache_file.' for writing.');
            return false;
            }
            
        }

// call the function like this
// here you will create a html page page_43.html in your pages directory.
// if you have the script in your webroot (http://mysite.com/) then the new page will be http://mysite.com/pages/page_43.html)

cache_url('http://mysite.com/page.php?id=43', 'page_43.html', 'pages');

Good Luck.
www.digital-ether.com

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.