Wednesday, July 06, 2005

Generate HTML with PHP

This coding is used to generate HTML page with PHP coding. Reasons of doing this are to

- reduce server load for a heavy traffic page
- improve search engine optimization with static page
- allow thousands of users to access without crash the db server

Step 1: build the HTML coding in PHP (dynamic)

$html = "html...................../html"

// $html is a variable that holds long generated HTML string

Step 2: generate the file with the HTML code and give a name to the file

$qfname=str_replace(" ","-",$quiz[title]);
$qfname=str_replace("?","",$qfname);

Step 3: write the file to the server

$fp=fopen("quiz/$user->username/$qfname.html","wb");
fwrite($fp,$html);
fclose($fp);

original source

No comments: