©ô«È·h®a¤½¥qµû»ùºôµû»ù²Ä¤@¦W¡A¼sÀò«È¤á¦nµû ¹stµû¡A¥Î¤ß¡B±M·~¬Ý±o¨£ | ªoº£¤uµ{¡AÁ¿¨s²Ó³¡×¾ã ¨¾¼é¯»¨ê¡A§K¶O¦ô»ù¡I |
PHP¥Í¦¨ÀRºA¶±¸Ô¸Ñ |
©ÐªF¡G·s¤â µoªí®É¶¡¡G2007-01-31 |
¬Ý¨ì«Ü¦hªB¤Í¦b¦UÓ¦a¤èµo©«°ÝPHP¥Í¦¨ÀRºA¤å³¹¨t²Îªº¤èªk¡A¥H«e´¿°µ¹L³o¼Ë¤@Ó¨t²Î¡A¹E½Í¨Ç¬Ýªk¡A¥H¨Ñ¦U¦ì°Ñ¦Ò¡C¦n¤F¡A§ÚÌ¥ý¦^ÅU¤@¨Ç°ò¥»ªº·§©À¡C ¡@¡@¤@¡APHP¸}¥»»P°ÊºA¶±¡C ¡@¡@PHP¸}¥»¬O¤@ºØ¦øªA¾¹ºÝ¸}¥»µ{¦¡¡A¥i³q¹L´O¤Jµ¥¤èªk»PHTML¤å¥ó²V¦X¡A¤]¥i¥HÃþ¡A¨ç¼Æ«Ê¸Ëµ¥§Î¦¡¡A¥H¼ÒªOªº¤è¦¡¹ï¥Î¤á½Ð¨D¶i¦æ³B²z¡CµL½×¥H¦óºØ¤è¦¡¡A¥¦ªº°ò¥»ì²z¬O³o¼Ëªº¡C¥Ñ«È¤áºÝ´£¥X½Ð¨D¡A½Ð¨D¬Y¤@¶±¡@----->¡@WEB¦øªA¾¹¤Þ¤J«ü©w¬ÛÀ³¸}¥»¶i¦æ³B²z¡@----->¡@¸}¥»³Q¸ü¤J¦øªA¾¹¡@----->¡@¥Ñ¦øªA¾¹«ü©wªºPHP¸ÑªR¾¹¹ï¸}¥»¶i¦æ¸ÑªR§Î¦¨HTML»y¨¥§Î¦¡¡@---->¡@±N¸ÑªR«áªºHTML»y¥y¥H¥]ªº¤è¦¡¶Ç¦^µ¹ÂsÄý¾¹¡C¥Ñ¦¹¤£Ãø¬Ý¥X¡A¦b¶±µo°e¨ìÂsÄý¾¹«á¡APHP´N¤£¦s¦b¤F¡A¤w³QÂà¤Æ¸ÑªR¬°HTML»y¥y¡C«È¤á½Ð¨D¬°¤@°ÊºA¤å¥ó¡A¨Æ¹ê¤W¨Ã¨S¦³¯u¥¿ªº¤å¥ó¦s¦b¦b¨ºùØ¡A¬OPHP¸ÑªR¦Ó¦¨¬Û¹ïÀ³ªº¶±¡AµM«áµo°e¦^ÂsÄý¾¹¡C³oºØ¶±³B²z¤è¦¡³QºÙ¬°¡§°ÊºA¶±¡¨¡C ¡@¡@¤G¡AÀRºA¶±¡C ¡@¡@ÀRºA¶±¬O«ü¦b¦øªA¾¹ºÝ½T¹ê¦s¦bªº¶È§tHTML¥H¤ÎJS¡ACSSµ¥«È¤áºÝ¹B¦æ¸}¥»ªº¶±¡C¥¦ªº³B²z¤è¦¡¬O¡C¥Ñ«È¤áºÝ´£¥X½Ð¨D¡A½Ð¨D¬Y¤@¶±¡@---->¡@WEB¦øªA¾¹½T»{¨Ã¸ü¤J¬Y¤@¶±¡@---->¡@WEB¦øªA¾¹±N¸Ó¶±¥H¥]ªº§Î¦¡¶Ç»¼¦^ÂsÄý¾¹¡C¥Ñ³o¤@¹Lµ{¡A§Ú̹ï¤ñ¤@¤U°ÊºA¶±¡A§Y¥i¤è²{¡C°ÊºA¶±»Ý¥ÑWEB¦øªA¾¹ªºPHP¸ÑªR¾¹¶i¦æ¸ÑªR¡A¦Ó¥B³q±`Áٻݳs±µ¼Æ¾Ú®w¡A¶i¦æ¼Æ¾Ú®w¦s¨ú¾Þ§@¡AµM«á¤~¯à§Î¦¨HTML»y¨¥¸ê°T¥]¡F¦ÓÀRºA¶±¡AµL¶·¸ÑªR¡AµL¶·³s±µ¼Æ¾Ú®w¡Aª½±µµo°e¡A¥i¤j¤j´î»´¦øªA¾¹À£¤O¡A´£°ª¦øªA¾¹t¸ü¯à¤O¡A¤j´T´£¨Ñ¶±¥´¶}³t«×©Mºô¯¸¾ãÅ饴¶}³t«×¡C¦ý¨ä¯ÊÂI¬O¡A¤£¯à°ÊºA¦a¹ï½Ð¨D¶i¦æ³B²z¡A¦øªA¾¹¤W¥²¶·½T¹ê¦s¦b¸Ó¤å¥ó¡C ¡@¡@¤T¡A¼ÒªO¤Î¼ÒªO¸ÑªR¡C ¡@¡@¼ÒªO§Y©|¥¼¶ñ¥R¤º®ehtml¤å¥ó¡C¨Ò¦p¡G ¡@temp.html Code: this is a { file } file's templets PHP³B²z¡G ¡@templetest.php Code: $title = "©ÝÁÚ°ê»Ú´ú¸Õ¼ÒªO"; $file = "TwoMax Inter test templet, author¡GMatrix@Two_Max"; ¡@$fp = fopen ("temp.html","r"); $content = fread ($fp,filesize ("temp.html")); $content .= str_replace ("{ file }",$file,$content); $content .= str_replace ("{ title }",$title,$content); echo $content; ?> ¡@¡@¼ÒªO¸ÑªR³B²z¡A§Y±N¸gPHP¸}¥»¸ÑªR³B²z«á±o¥Xªºµ²ªG¶ñ¥R(content)¶i¼ÒªOªº³B²z¹Lµ{¡C³q±`ɧU©ó¼ÒªOÃþ¡C¥Ø«e¸û¬y¦æªº¼ÒªO¸ÑªRÃþ¦³phplib¡Asmarty¡Afastsmartyµ¥µ¥¡C¼ÒªO¸ÑªR³B²zªºì²z³q±`¬°´À´«¡C¤]¦³¨Çµ{¦¡û²ßºD±N§PÂ_¡A°j°éµ¥³B²z©ñ¶i¼ÒªO¤å¥ó¤¤¡A¥Î¸ÑªRÃþ³B²z¡A¨å«¬À³¥Î¬°block·§©À¡A²³æ¨Ó»¡§Y¬°¤@Ó°j°é³B²z¡C¥ÑPHP¸}¥»«ü©w°j°é¦¸¼Æ¡A¦p¦ó°j°é¥N¤Jµ¥¡A¦A¥Ñ¼ÒªO¸ÑªRÃþ¨ãÅé¹ê¬I³o¨Ç¾Þ§@¡C ¡@¡@¦n¤F¡A¹ï¤ñ¹LÀRºA¶±»P°ÊºA¶±¦U¦ÛªºÀu¦H¡A²{¦b§ÚÌ´N¨Ó»¡»¡¡A¦p¦ó¥ÎPHP¥Í¦¨ÀRºA¤å¥ó¡C ¡@¡@PHP¥Í¦¨ÀRºA¶±¨Ã¤£¬O«üPHPªº°ÊºA¸ÑªR¡A¿é¥XHTML¶±¡A¦Ó¬O«ü¥ÎPHP³Ð«ØHTML¶±¡C¦P®É¦]¬°HTMLªº¤£¥i¼g©Ê¡A§Ú̳ЫتºHTMLY¦³×§ï¡A«h»Ý§R±¼«·s¥Í¦¨§Y¥i¡C(·íµM§A¤]¥i¥H¿ï¾Ü¥Î¥¿«h¶i¦æקï¡A¦ýÓ¤H»{¬°¨º¼Ë°µË¤£¦p§R±¼«·s¥Í¦¨¨Ó±o§Ö±¶¡A¦³¨Ç±o¤£Àv¥¢¡C) ¡@¡@¨¥Âk¥¿¶Ç¡C¥Î¹LPHP¤å¥ó¾Þ§@¨ç¼ÆªºPHP FANSª¾¹D¡APHP¤¤¦³¤@Ó¤å¥ó¾Þ§@¨ç¼Æfopen¡A§Y¥´¶}¤å¥ó¡CY¤å¥ó¤£¦s¦b¡A«h¹Á¸Õ³Ð«Ø¡C³o§Y¬OPHP¥i¥H¥Î¨Ó³Ð«ØHTML¤å¥óªº²z½×°ò¦¡C¥un¥Î¨Ó¦s©ñHTML¤å¥óªº¤å¥ó§¨¦³¼g³\¥iÅv(§Y³\¥iÅv©w¸q0777)¡A§Y¥i³Ð«Ø¤å¥ó¡C¡]°w¹ïUNIX¨t²Î¦Ó¨¥¡AWin¨t²ÎµL¶·¦Ò¼{¡C¡^¤´¥H¤W¨Ò¬°¨Ò¡AY§ÚÌקï³Ì«á¤@¥y¡A¨Ã«ü©w¦btest¥Ø¿ý¤U¥Í¦¨¤@Ó¦W¬°test.htmlªºÀRºA¤å¥ó¡G Code: $title = "©ÝÁÚ°ê»Ú´ú¸Õ¼ÒªO"; $file = "TwoMax Inter test templet, author¡GMatrix@Two_Max"; ¡@$fp = fopen ("temp.html","r"); $content = fread ($fp,filesize ("temp.html")); $content .= str_replace ("{file}",$file,$content); $content .= str_replace ("{title}",$title,$content); // echo $content; $filename = "test/test.html"; $handle = fopen ($filename,"w"); //¥´¶}¤å¥ó«ü°w¡A³Ð«Ø¤å¥ó /* ¡@Àˬd¤å¥ó¬O§_³Q³Ð«Ø¥B¥i¼g */ if (!is_writable ($filename)){ die ("¤å¥ó¡G".$filename."¤£¥i¼g¡A½ÐÀˬd¨äÄݩʫ᫸աI"); } if (!fwrite ($handle,$content)){ //±N¸ê°T¼g¤J¤å¥ó die ("¥Í¦¨¤å¥ó".$filename."¥¢±Ñ¡I"); } fclose ($handle); //Ãö³¬«ü°w die ("³Ð«Ø¤å¥ó".$filename."¦¨¥\¡I"); ?> ¡@¡@¹ê»ÚÀ³¥Î¤¤±`¨£°ÝÃD¸Ñ¨M¤è®×°Ñ¦Ò¡G ¡@¡@¤@¡A¤å³¹¦Cªí°ÝÃD¡G ¡@¡@ ¡@¡@¦b¼Æ¾Ú®w¤¤³Ð«Ø¦r¬q¡A°O¿ý¤å¥ó¦W¡A¨C¥Í¦¨¤@Ó¤å¥ó¡A±N¦Û°Ê¥Í¦¨ªº¤å¥ó¦W¦s¤J¼Æ¾Ú®w¡A¹ï©ó±ÀÂˤ峹¡A¥u»Ý«ü¦V¦s©ñÀRºA¤å¥óªº«ü©w¤å¥ó§¨¤¤ªº¸Ó¶±§Y¥i¡C§Q¥ÎPHP¾Þ§@³B²z¤å³¹¦Cªí¡A¦s¬°¦r²Å¦ê¡A¥Í¦¨¶±®É´À´«¦¹¦r²Å¦ê§Y¥i¡C¦p¡A¦b¶±¤¤©ñ¸m¤å³¹¦Cªíªºªí®æ¥[¤J¼Ð°O{articletable}¡A¦Ó¦bPHP³B²z¤å¥ó¤¤¡G Code: $title = "©ÝÁÚ°ê»Ú´ú¸Õ¼ÒªO"; $file = "TwoMax Inter test templet, author¡GMatrix@Two_Max"; ¡@$fp = fopen ("temp.html","r"); $content = fread ($fp,filesize ("temp.html")); $content .= str_replace ("{file}",$file,$content); $content .= str_replace ("{title}",$title,$content); // ¥Í¦¨¦Cªí¶}©l $list = ''; $sql = "select id,title,filename from article"; $query = mysql_query ($sql); while ($result = mysql_fetch_array ($query)){ $list .= ''.$result['title'].' '; } $content .= str_replace ("{articletable}",$list,$content); //¥Í¦¨¦Cªíµ²§ô // echo $content; $filename = "test/test.html"; $handle = fopen ($filename,"w"); //¥´¶}¤å¥ó«ü°w¡A³Ð«Ø¤å¥ó /* ¡@Àˬd¤å¥ó¬O§_³Q³Ð«Ø¥B¥i¼g */ if (!is_writable ($filename)){ die ("¤å¥ó¡G".$filename."¤£¥i¼g¡A½ÐÀˬd¨äÄݩʫ᫸աI"); } if (!fwrite ($handle,$content)){ //±N¸ê°T¼g¤J¤å¥ó die ("¥Í¦¨¤å¥ó".$filename."¥¢±Ñ¡I"); } fclose ($handle); //Ãö³¬«ü°w die ("³Ð«Ø¤å¥ó".$filename."¦¨¥\¡I"); ?> ¡@¡@¤G¡A¤À¶°ÝÃD¡C ¡@¡@¦p§ÚÌ«ü©w¤À¶®É¡A¨C¶20½g¡C¬Y¤lÀW¹D¦Cªí¤º¤å³¹¸g¼Æ¾Ú®w¬d¸ß¬°45±ø¡A«h¡Aº¥ý§Ú̳q¹L¬d¸ß±o¨ì¦p¤U°Ñ¼Æ¡G1¡AÁ`¶¼Æ¡F2¡A¨C¶½g¼Æ¡C²Ä¤G¨B¡Afor ($i = 0; $i < allpages; $i++)¡A¶±¤¸¯ÀÀò¨ú¡A¤ÀªR¡A¤å³¹¥Í¦¨¡A³£¦b¦¹°j°é¤¤°õ¦æ¡C¤£¦Pªº¬O¡Adie ("³Ð«Ø¤å¥ó".$filename."¦¨¥\¡I";³o¥y¥h±¼¡A©ñ¨ì°j°é«áªºÅã¥Ü¡A¦]¬°¸Ó»y¥y±N¤¤¤îµ{¦¡°õ¦æ¡C¨Ò¡G Code: $fp = fopen ("temp.html","r"); $content = fread ($fp,filesize ("temp.html")); $onepage = '20'; $sql = "select id from article where channel='$channelid'"; $query = mysql_query ($sql); $num = mysql_num_rows ($query); $allpages = ceil ($num / $onepage); for ($i = 0;$i<$allpages; $i++){ if ($i == 0){ $indexpath = "index.html"; } else { $indexpath = "index_".$i."html"; } $start = $i * $onepage; $list = ''; $sql_for_page = "select name,filename,title from article where channel='$channelid' limit $start,$onepage"; $query_for_page = mysql_query ($sql_for_page); while ($result = $query_for_page){ $list .= ''.$title.' '; } $content = str_replace ("{articletable}",$list,$content); if (is_file ($indexpath)){ @unlink ($indexpath); //Y¤å¥ó¤w¦s¦b¡A«h§R°£ } $handle = fopen ($indexpath,"w"); //¥´¶}¤å¥ó«ü°w¡A³Ð«Ø¤å¥ó /* ¡@ Àˬd¤å¥ó¬O§_³Q³Ð«Ø¥B¥i¼g */ if (!is_writable ($indexpath)){ echo "¤å¥ó¡G".$indexpath."¤£¥i¼g¡A½ÐÀˬd¨äÄݩʫ᫸աI"; //קאּecho } if (!fwrite ($handle,$content)){ //±N¸ê°T¼g¤J¤å¥ó echo "¥Í¦¨¤å¥ó".$indexpath."¥¢±Ñ¡I"; //קאּecho } fclose ($handle); //Ãö³¬«ü°w } fclose ($fp); die ("¥Í¦¨¤À¶¤å¥ó§¹¦¨¡A¦p¥Í¦¨¤£§¹¥þ¡A½ÐÀˬd¤å¥ó³\¥iÅv¨t²Î«á«·s¥Í¦¨¡I"); ?> ¡@¡@¤jP«ä¸ô¦p¦¹¡A¨ä¤¤¦p¨ä¥L¼Æ¾Ú¥Í¦¨¡A¼Æ¾Ú¿é¤J¿é¥XÀˬd¡A¤À¶¤º®e«ü¦Vµ¥¥i°u±¡¦b¶±¤¤¥[¤J¡C ¡@¡@¦b¹ê»Ú¤å³¹¨t²Î³B²z¹Lµ{·í¤¤¡AÁÙ¦³³\¦h°ÝÃD¦³«Ý¦Ò¼{¡A»P°ÊºA¶±¤£¦P¤§³B¡A»Ýª`·Nªº¦a¤èÁÙ¦³«Ü¦h¡C¦ý¤jP«ä¸ô§Y¬O¦p¦¹¡A¨ä¥L¤è±¥iÁ|¤@¤Ï¤T¦Ó±o¡C ¡@¡@¥t¡GÜ«P§¹¦¨¡]«ÝÄò¡^¡A¤£¨¬¤§³BÁٽаª¤â«ü¥¿¡C |
|
1 ¼Ó¦í¤á¡G¤p¤p µoªí®É¶¡¡G2007-02-03 |
¦bºô¸ô¤W(80x86 blog)¬Ý¨ìªº¤@½g¤å³¹¡AÓ¤Hı±o«Ü¦³»ùÈ¡A¨Ã¤]è¦n²Å¦XÓ¤HCaseªº»Ý¨D! ²Ä¤@ºØ¡G§Q¥Î¼ÒªO¡C¥Ø«ePHPªº¼ÒªO¥i¥H»¡¬O«Ü¦h¤F¡A¦³¥\¯à±j¤jªºsmarty¡AÁÙ¦³Â²³æ©ö¥Îªºsmarttemplateµ¥¡C¥¦Ì¨C¤@ºØ¼ÒªO¡A³£¦³¤@ÓÀò¨ú¿é¥X¤º®eªº¨ç¼Æ¡C§Ú̥ͦ¨ÀRºA¶±ªº¤èªk¡A´N¬O§Q¥Î¤F³oÓ¨ç¼Æ¡C¥Î³oÓ¤èªkªºÀuÂI¬O¡A¥N½X¤ñ¸û²M´·¡A¥iŪ©Ê¦n¡C PHP¥N½XÁ|¨Ò¡G ¡@require("smarty/Smarty.class.php"); ¡@$t = new Smarty; ¡@$t->assign("title","Hello World!"); ¡@$content = $t->fetch("templates/index.htm"); //³o¸Ìªº fetch() ´N¬OÀò¨ú¿é¥X¤º®eªº¨ç¼Æ,²{¦b$contentÅܶq¸Ì±,´N¬OnÅã¥Üªº¤º®e¤F ¡@$fp = fopen("archives/2005/05/19/0001.html", "w"); ¡@fwrite($fp, $content); ¡@fclose($fp); ?> ²Ä¤GºØ¤èªk¡G§Q¥Îob¨t¦Cªº¨ç¼Æ¡C³o¸Ì¥Î¨ìªº¨ç¼Æ¥Dn¬O ob_start(), ob_end_flush(), ob_get_content(),¨ä¤¤ob_start()¬O¥´¶}ÂsÄý¾¹½w½Ä°Ïªº·N«ä¡A¥´¶}½w½Ä«á¡A©Ò¦³¨Ó¦ÛPHPµ{§Çªº«D¤å¥óÀY«H®§§¡¤£·|µo°e¡A¦Ó¬O «O¦s¦b¤º³¡½w½Ä°Ï¡Aª½¨ì§A¨Ï¥Î¤Fob_end_flush().¦Ó³o¸Ì³Ì«nªº¤@Ó¨ç¼Æ¡A´N¬Oob_get_contents(),³oÓ¨ç¼Æªº§@¥Î¬OÀò¨ú ½w½Ä°Ïªº¤º®e¡A¬Û·í©ó¤W±ªº¨ºÓfetch(),¹D²z¤@¼Ëªº¡C PHP¥N½XÁ|¨Ò¡G ¡@ob_start(); ¡@echo "Hello World!"; ¡@$content = ob_get_contents();¡@//¨ú±ophp¶±¿é¥Xªº¥þ³¡¤º®e ¡@$fp = fopen("archives/2005/05/19/0001.html", "w"); ¡@fwrite($fp, $content); ¡@fclose($fp); ?> |
©m¦W¡G | |||
§G§i¤º®e¡G | |||
¨ä¥L¿ï¶µ: | |||
|