鍑忓皯鏈嶅姟鍣ㄥ帇鍔沺hp鐢熸垚闈欐€亁ml鏂囦欢

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鍑忓皯鏈嶅姟鍣ㄥ帇鍔沺hp鐢熸垚闈欐€亁ml鏂囦欢相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/%e5%b9%b3%e8%a1%a1' title='骞宠 '>骞宠    鏂板缓   spl   鍔ㄦ墜   exe   red   鍑嗗宸ヤ綔   error   涓嶇敤   

涓€銆佸紩 瑷€

 

鍦ㄩ€熷害涓?闈欐€侀〉闈㈣姣斿姩鎬侀〉闈㈢殑姣旀柟php蹇緢澶?杩欐槸姣棤鐤戦棶鐨?浣嗘槸鐢变簬闈欐€侀〉闈㈢殑鐏垫椿鎬ц緝宸?濡傛灉涓嶅€熷姪鏁版嵁搴撴垨鍏朵粬鐨勮澶囦繚瀛樼浉鍏充俊鎭殑璇?鏁翠綋鐨勭鐞嗕笂姣旇緝绻佺悙,姣旀柟淇敼缂栬緫.姣旀柟闃呰鏉冮檺闄愬埗绛?浣嗘槸,瀵瑰簲涓€浜涙垜浠粡甯搁棰戜娇鐢ㄧ殑鏂囦欢,姣旀柟璇?寮€鍙戠殑鏂伴椈鍙戝竷绯荤粺,鎴戜滑涓嶅笇鏈涘緢澶氱敤鎴烽兘璇诲彇鏁版嵁搴撴墠鏄剧ず缁撴灉,杩欐牱涓€鏂归潰娑堣€椾簡鏈嶅姟鍣ㄧ殑璧勬簮,鍙︿竴鏂归潰鍗犲幓浜嗘祻瑙堣€呭ぇ閲忓彲璐电殑鍝嶅簲鏃堕棿,鎵€鏈?鏈変簡"闈欐€侀〉闈㈣瘽"鐨勫仛娉?褰撳墠寰堝缃戠珯閮介噰鐢ㄨ繖绉嶆妧鏈?涓€鑸兘鏄敱绠$悊鍚庡彴鎺у埗,鎴栬€呯敓鎴恏tml鐩存帴鏄剧ず,鎴栬€厁html鐢╟ss鎺у埗鏄剧ず,鎴栬€呯敓鎴恱ml鐢▁slt鏄剧ず,杩欎簺鎶€鏈兘涓嶆槸闅剧殑,鍦ㄨ繖閲屾垜灏辨祬鏄剧殑璇磋鐢熸垚html鐨勬柟娉?

 

浜屻€侀澶囩煡璇?/p>

 

妯℃澘鎶€鏈?

 

[PHP] 妯℃澘寮曟搸Smarty娣卞叆娴呭嚭浠嬬粛 --2005-12-31

[PHP] 绗戣皥閰嶇疆,浣跨敤Smarty鎶€鏈?--2006-01-04

 

缂撳瓨鎶€鏈?

 

鏈変簺淇℃伅姣旀柟缁忓父涓嶅彉鐨?浣嗘槸杩樻槸鑳藉彉鐨勪俊鎭斁鍦ㄧ紦瀛樹腑浠ュ姞蹇樉绀洪€熷害,杩欐槸寰堟湁浠峰€肩殑,鎵€璋撶殑缂撳瓨,閫氫織鐨勭悊瑙e氨鏄竴浜涗繚瀛樺湪鏈嶅姟鍣ㄧ鐨勫叡鐢ㄤ俊鎭?瀹冩槸浜庢湇鍔″櫒鍚岀敓姝荤殑,鎴戜滑鍦ㄤ繚瀛樼紦瀛樼殑鏃跺€欏彲浠ユ寚瀹氫笅娆℃洿鏂扮殑鏃堕棿鐨勫垽鏂?姣旀柟瑕佸湪5鍒嗛挓鏇存柊涓€娆?鍙互璁板綍涓婃鏇存柊鐨勬椂闂?鍜屽綋鍓嶆椂闂存瘮杈?濡傛灉澶т簬 5 鍒嗛挓 ,璇诲彇鏁版嵁搴?鏇存柊鎹㈡垚,鍚﹀垯鐩存帴璇诲彇缂撳瓨鏁版嵁,褰撶劧,缂撳瓨闇€瑕佸鎴风鐢ㄦ埛婵€娲荤殑,鍙渶涓€娆?

 

ob_start()鍑芥暟:鎵撳紑杈撳嚭缂撳啿鍖?

鍑芥暟鏍煎紡 void ob_start(void)

璇存槑锛氬綋缂撳啿鍖烘縺娲绘椂锛屾墍鏈夋潵鑷狿HP绋嬪簭鐨勯潪鏂囦欢澶翠俊鎭潎涓嶄細鍙戦€侊紝鑰屾槸淇濆瓨鍦ㄥ唴閮ㄧ紦鍐插尯銆備负浜嗚緭鍑虹紦鍐插尯鐨勫唴瀹癸紝鍙互浣跨敤ob_end_flush()鎴杅lush()杈撳嚭缂撳啿鍖虹殑鍐呭銆?/p>

 

Flush锛氬埛鏂扮紦鍐插尯鐨勫唴瀹癸紝杈撳嚭銆?/p>

鍑芥暟鏍煎紡锛歠lush()

璇存槑锛氳繖涓嚱鏁扮粡甯镐娇鐢?鏁堢巼寰堥珮銆?/p>

 

ob_get_contents 锛氳繑鍥炲唴閮ㄧ紦鍐插尯鐨勫唴瀹广€?/p>

鍑芥暟鏍煎紡锛歴tring ob_get_contents(void)

璇存槑锛氳繖涓嚱鏁颁細杩斿洖褰撳墠缂撳啿鍖轰腑鐨勫唴瀹癸紝濡傛灉杈撳嚭缂撳啿鍖烘病鏈夋縺娲?鍒欒繑鍥?FALSE.

 

ob_get_length锛氳繑鍥炲唴閮ㄧ紦鍐插尯鐨勯暱搴︺€?/p>

鍑芥暟鏍煎紡锛歩nt ob_get_length(void)

璇存槑锛氳繖涓嚱鏁颁細杩斿洖褰撳墠缂撳啿鍖轰腑鐨勯暱搴︼紱鍜宱b_get_contents涓€鏍凤紝濡傛灉杈撳嚭缂撳啿鍖烘病鏈夋縺娲?鍒欒繑鍥?FALSE.

 

ob_end_clean锛氬垹闄ゅ唴閮ㄧ紦鍐插尯鐨勫唴瀹癸紝骞朵笖鍏抽棴鍐呴儴缂撳啿鍖?/p>

鍑芥暟鏍煎紡锛歷oid ob_end_clean(void)

璇存槑锛氳繖涓嚱鏁颁笉浼氳緭鍑哄唴閮ㄧ紦鍐插尯鐨勫唴瀹硅€屾槸鎶婂畠鍒犻櫎

 

ob_end_flush:鍙戦€佸唴閮ㄧ紦鍐插尯鐨勫唴瀹瑰埌娴忚鍣紝骞朵笖鍏抽棴杈撳嚭缂撳啿鍖?/p>

鍑芥暟鏍煎紡锛歷oid ob_end_flush(void)

璇存槑锛氳繖涓嚱鏁板彂閫佽緭鍑虹紦鍐插尯鐨勫唴瀹癸紙濡傛灉鏈夌殑璇濓級

 

ob_implicit_flush锛氭墦寮€鎴栧叧闂粷瀵瑰埛鏂?/p>

鍑芥暟鏍煎紡锛歷oid ob_implicit_flush ([int flag])

璇存槑锛氶粯璁や负鍏抽棴缂撳啿鍖猴紝鎵撳紑缁濆杈撳嚭鍚庯紝姣忎釜鑴氭湰杈撳嚭閮界洿鎺ュ彂閫佸埌娴忚鍣紝涓嶅啀闇€瑕佽皟鐢?flush()

 

鏂囦欢鍐欏叆:

 

int fwrite ( resource handle, string string [, int length] )

fwrite() 鎶?string 鐨勫唴瀹瑰啓鍏?鏂囦欢鎸囬拡 handle 澶勩€?濡傛灉鎸囧畾浜?length锛屽綋鍐欏叆浜?length 涓瓧鑺傛垨鑰呭啓瀹屼簡 string 浠ュ悗锛屽啓鍏ュ氨浼氬仠姝紝瑙嗕箮鍏堢鍒板摢绉嶆儏鍐点€?/p>

fwrite() 杩斿洖鍐欏叆鐨勫瓧绗︽暟锛屽嚭鐜伴敊璇椂鍒欒繑鍥?FALSE 銆?/p>

鐩稿叧鍙傝€冨畼鏂圭綉绔? 鏂囦欢鍙傝€?/p>

 

涓夈€佽В鍐虫柟妗?/p>

 

鎬濊矾:寮€鍚?ob_start缂撳啿,褰撳凡缁忚皟鍑烘暟鎹殑鏃跺€欒幏鍙?ob_get_contents,鐒跺悗鐢熸垚闈欐€侀〉,ob_end_clean娓呴櫎缂撳啿.ok,灏辫繖涔堟潵,鏉ョ湅涓€涓緥瀛?php+mysql鐨勭粨鍚?:

 

鍒涘缓鏁版嵁搴?

 

CREATE TABLE `bihtml` (

`id` int(11) NOT NULL auto_increment,

`szdtitle` varchar(16) NOT NULL,

`szdcontent` text NOT NULL,

PRIMARY KEY (`id`)

) TYPE=MyISAM;

鑾峰彇褰撳墠鐨処D,骞跺鍏ユā鏉?

 

 

 

 

ob_start();

$id=_POST[鈥榠d鈥榏

if(!isset($id)&&is_integer($id))

{

@$db=new mysqli(鈥榣ocalhost鈥?鈥榬oot鈥?鈥榓dmin鈥?鈥榖ihtml鈥?;

$result=$db->fetch_one_array("select * from szd_bi where id=鈥?id鈥?);

if(!empty($result))

{

$tmp->assign(array(

"Szdtitle",htmlspecialchars($result[鈥榯itles鈥榏),

"Szdcontent",$result[鈥榯itles鈥榏));

}

$tpl->display(鈥榙efault_1.tpl鈥?;

$this_my_f= ob_get_contents(); //姝ゅ鍏抽敭

ob_end_clean();

$filename = "$id.html";

if(tohtmlfile_cjjer($filename,$this_my_f))

echo "鐢熸垚鎴愬姛 $filename";

else

echo "鐢熸垚璇嗗埆";

}

}

 

//鎶婄敓鎴愭枃浠剁殑杩囩▼鍐欏嚭鍑芥暟

function tohtmlfile_cjjer($file_cjjer_name,$file_cjjer_content)

{

if (is_file ($file_cjjer_name)){

@unlink ($file_cjjer_name);

}

$cjjer_handle = fopen ($file_cjjer_name,"w");

if (!is_writable ($file_cjjer_name)){

return false;

}

if (!fwrite ($cjjer_handle,$file_cjjer_content)){

return false;

}

fclose ($cjjer_handle); //鍏抽棴鎸囬拡

return $file_cjjer_name;

}

 

鍥涖€佽鏄庝簨椤?/p>

 

1: 涓€鑸缓璁鐞嗗憳娣诲姞鏁版嵁鐨勬椂鍊欏氨鐢熸垚闈欐€侀〉闈?鍙互鑰冭檻璁板綍鐢熸垚鐨勬枃浠跺悕娆″拰璺緞.

 

2: php涓昏鏄?ob_starts()鍜?ob_get_contents,鐢熸垚闈欐€侀〉闈㈢殑鏃跺€欏緢鏈夌敤,褰撶劧涔熷彲浠ヨ€冭檻璋冨嚭鏁版嵁搴撶洿鎺ユ浛鎹㈡ā鏉块噷闈㈢殑鍙橀噺涔熸槸鍙互鐨?

 

3: 涓昏鐨勬ā鏉夸娇鐢╯marty,phplib閮芥槸鍙互鐨?smarty浣跨敤姣旇緝绠€鏄?

 

*****************************************************

 

1.绠$悊鍚庡彴娣诲姞璁板綍鏃讹紝鐩存帴鐢熸垚鐩爣html椤甸潰锛屽苟涓斿墠鍙拌皟鐢ㄨ繛鎺ョ洿鎺ユ寚鍚戠敓鎴愮殑html椤甸潰銆傝繖绉嶆柟娉曠▼浼樼偣鏄▼搴忔晥鐜囨渶楂樸€?/p>

鏈嶅姟鍣ㄨ礋鑽疯交锛屼笉杩囩敱浜庣敓鎴愮殑鏄函闈欐€侀〉闈紝涓€鏃﹂〉闈㈡牱寮?妯$増鍙奵ss=theme)涓婃湁鎵€鏀瑰姩灏卞繀椤婚噸鏂扮敓鎴愭墍鏈夌殑鍐呭椤点€?/p>

鎵€浠ュ疄闄呬娇鐢ㄤ腑搴旂敤涓€鑸笉鏄お澶氥€傛洿澶氱殑鏄娇鐢╦s,ssi,xml/xsl绛夊鎴风鎵嬫锛岀敓鎴愮殑闈欐€佹枃浠朵腑浠呬繚瀛樻暟鎹紝涓嶆秹鍙婃牱寮忥紝

杩欐牱鑳借揪鍒伴€熷害鍜岀淮鎶ゆ€х殑骞宠 锛屼笉杩囩浉瀵瑰墠鍚庡彴绋嬪簭瑕佸鏉備簺锛堝簲鐢ㄨ繖绉嶆柟娉曟椂锛岀敱浜庡唴瀹逛负绾潤鎬侊紝鍙互鎼厤鍗曠嫭缂栬瘧鐨勭函闈欐€佺殑apache浣跨敤銆傘€傛晥鐜囧拰璧勬簮鍗犵敤涓婃瘮鍖呭惈鍔ㄦ€佸唴瀹规敮鎸佺殑瑕佹洿浣筹級

====

琛ュ厖:

a.涓婇潰璇寸殑鏀瑰姩鏍峰紡锛岃閲嶆柊鐢熸垚鎵€鏈夌殑鍐呭椤碉紝鍙互閫氳繃锛?/p>

>>>>鍦ㄥ彲浠ュ湪姣忎釜鐢熸垚鐨勯〉闈㈠唴宓屽叆涓€涓?lt;scr墨ptsrc=XXX.php?id=xxx&template=red></scr墨pt>鏉ュ垽鏂槸鍚﹂渶瑕侀噸鏂扮敓鎴愯椤甸潰銆?/p>

>>>>apache鐨凟rrorDocument404鍔熻兘锛屼絾鏄繖閲屽墠鍙伴摼鎺ユ槸鎸囧悜html鐨勶紝濡傛灉璇tml涓嶅瓨鍦紝浼氶€氳繃apache鐨勬枃浠朵笉瀛樺湪閲嶅畾鍚戝埌404澶勭悊绋嬪簭鐨勫姛鑳介噸鏂扮敓鎴恏tml

(娉細httpd.conf鍔燛rrorDocument404/errprocess.php鎸囦护)锛屽埄鐢ㄨ繖涓姛鑳藉彲浠ヨВ鍐充慨鏀圭綉绔欐牱寮忕殑鏃跺€欙紝瑕佹洿鏂版墍鏈夌敓鎴愮殑html鏂囦欢鐨勯棶棰橈紝

灏嗘暣涓猻tatic鏂囦欢澶瑰垹闄ゅ嵆鍙€?/p>

b.閫氳繃宓屽叆<scr墨pt></scr墨pt>js鏉ヨ皟鐢╬hp鐨勬柟寮忥紝鏇存敼璁稿闇€瑕佸彉鍖栫殑鍦版柟锛堝鐐瑰嚮鐜囦箣绫荤殑)

銆€銆€2.鍓嶅彴璁块棶閾炬帴鎸囧悜php绋嬪簭锛宲hp绋嬪簭棣栧厛妫€鏌ユ槸鍚﹀瓨鍦ㄧ浉搴旂殑闈欐€佹枃浠躲€傚鏋滈潤鎬佹枃浠朵笉瀛樺湪銆傚垯鐢熸垚骞堕噸瀹氬悜鑷虫鏂囦欢锛屽惁鍒欑洿鎺ラ噸瀹氬悜銆?/p>

杩欑鏂规硶瀹為檯浣跨敤涓竴鑸拰apache鐨剈rl_rewrite鍔熻兘涓€璧蜂娇鐢ㄣ€傚皢php鐨勬枃浠跺湴鍧€閲嶆樉绀轰负html鐨勫舰寮忥紝鏈夊埄浜庢悳绱㈠紩鎿庣殑妫€绱€?/p>

杩欑鏂规硶鍦ㄦ晥鐜囦笂鐣ユ湁鎹熷け锛屼笉杩囩▼搴忕粨鏋勭畝鍗曪紝渚夸簬璋冩暣锛屽湪璁块棶閲忎笉鏄緢澶ф椂浣跨敤寰堝悎閫傘€?/p>

 

娉ㄦ剰浜嬮」锛?/p>

鎵€鏈夌敓鎴愮殑html鏂囦欢閮介泦涓斁鍒颁竴涓枃浠跺す锛屽叾涓繕搴旇娉ㄦ剰鐢熸垚鏂囦欢濡傛灉寰堝鐨勮瘽锛堝璁哄潧锛夛紝璁块棶鍏朵腑涓€涓猦tm鏂囦欢锛屽皢浼氬彉寰楀緢鎱紝

閭d箞鏈€濂介€氳繃

>>>>鎸夋棩鏈熸潵鍒嗛殧鏂囦欢澶癸紝濡俿tatic/2004/11/18/0001.htm

>>>>瀵瑰笘瀛恑d鏍规嵁鏁版嵁搴撲腑瀛楁闀垮害鍋歴tr_pad锛氭瘮鏂硅id涓?23456锛屾暟鎹簱涓负int(11),鍒檌d澶勭悊涓?0000123456,鑰冭檻鍒發inux涓嬩竴鑸悓涓€涓嬫枃浠跺埌杈惧洓浣嶆暟浼氭湁鎬ц兘褰卞搷锛屽鍏跺仛鍒囧壊锛屾渶鍚庤矾寰勪负static/00/000/123/456.html

 

 

 

 

------------------------------------------------------------------------

 

娴呰皥PHP鐢熸垚闈欐€侀〉鐨勪袱绉嶆柟娉?/p>

 

鏈€杩戜綔鐨勪竴涓」鐩腑鐢ㄥ埌浜嗕袱绉嶇敤PHP鐢熸垚闈欐€侀〉闈㈢殑鏂规硶锛屽洖鎯宠捣褰撳垵鑷繁杩樹笉鐭ラ亾濡備綍鐢熸垚闈欐€侀〉闈㈢殑杩锋儤锛屼互鍙婄湅涓嶆噦楂樻墜鍐欑殑鏂囩珷鐨勭棝鑻︼紝瑙夊緱鑷繁鏈夊繀瑕佺珯鍑烘潵涓鸿繕涓嶇煡閬撳浣曠敓鎴愰潤鎬侀〉鐨刾hper鍐欎竴涓€氫織鐐规枃绔狅紝浠ュ府鍔╀粬浠敖蹇帉鎻¤繖涓ソ涓滆タ銆?/p>

 

鍦ㄦ垜涔嬪墠鎵€瑙佺殑鏂囩珷涓涓嶆槸鐢ㄤ唬鐮佸爢鐮岀┖闂村氨鏄敤楂樻墜涓庨珮鎵嬩氦娴佺敤鐨勮瑷€璁╂柊浜烘湜鑰岀敓鍗淬€傚洜姝ゆ湰鏂囧敖閲忔妸鏁翠綋鎬濊矾璇村緱璇﹀敖鐐广€?/p>

 

涓ょ鏂规硶绠€鍗曡鏄庡涓嬶細

1锛?浣跨敤鏂囦欢鍑芥暟寰楀埌闈欐€侀〉闈㈢殑妯℃澘瀛楃涓诧紝鐒跺悗鐢╯tr_replace鍑芥暟灏嗛渶瑕佹浛鎹㈢殑涓滆タ鏇挎崲浜嗗啀鍐欏叆鍒版柊鐨勬枃浠朵腑銆?/p>

2锛?鍒╃敤PHP鐨勮緭鍑烘帶鍒跺嚱鏁帮紙Output Control锛夊緱鍒伴潤鎬侀〉闈㈠瓧绗︿覆锛屽啀鍐欏叆鍒版柊鐨勬枃浠朵腑銆?/p>

 

涓嬮潰寮€濮嬭缁嗙殑璇存槑銆?/p>

 

涓€锛?鍒╃敤妯℃澘鐢熸垚

 

浠€涔堟槸妯℃澘锛熷鏋滃ぇ瀹朵娇鐢ㄨ繃Dreamwerver涓殑"鍙﹀瓨涓烘ā鏉?灏卞簲璇ョ煡閬撴ā鏉挎槸鐢ㄦ潵缁熶竴椋庢牸鐨勪笢瑗裤€傚畠鍙浣犱慨鏀归〉闈㈢殑鏌愪竴閮ㄥ垎锛屽綋鐒惰繖"鏌愪竴閮?鍒?鏄敱浣犳潵纭畾鐨勩€傛湰鏂囧湪杩欒鐨勬ā鏉夸篃灏辨槸杩欎釜鎰忔€濄€傦紙姝ゅ锛孭HP妯℃澘鎶€鏈繕鍖呮嫭phplib銆乻marty绛夌瓑锛岃繖涓嶆槸鏈枃鎵€璇村唴瀹逛簡锛?/p>

 

鎶婃ā鏉跨殑姒傚康缁撳悎鏈枃鍐嶈寰楀叿浣撲竴鐐瑰氨鏄細缇庡伐鍏堝仛濂戒竴涓〉闈紝鐒跺悗鎴戜滑鎶婅繖涓〉闈㈠綋浣滄ā鏉匡紙瑕佹敞鎰忕殑鏄繖涓ā鏉垮氨娌″繀瑕佷娇鐢?lt;!-- TemplateBeginEditable name="EditRegion3" -->EditRegion3<!-- TemplateEndEditable -->杩欐牱鐨勪唬鐮佷簡锛岃繖绉嶄唬鐮佹槸Dreamwerver涓轰簡鏂逛究鑷繁璁捐鑰屽紕鐨勬爣璇嗭級锛屾妸杩欎釜妯℃澘涓垜浠渶瑕佹敼鍙樼殑鍦版柟鐢ㄤ竴涓笌HTML鍙互鍖哄垎鐨?瀛楃浠f浛锛屽"{title}"銆?[title]"銆傚湪鐢熸垚闈欐€侀〉闈㈢殑鏃跺€欏彧闇€瑕佹妸鏁版嵁鍜岃繖浜涘瓧绗︿覆鏇挎崲鍗冲彲銆傝繖灏辨槸妯℃澘鐨勫惈涔変簡銆?/p>

 

涓嬮潰鏉ヨ涓€涓嬪叿浣撶殑瀹炵幇鎬濊矾锛氬仛涓€涓ā鏉库€曗€曞湪妯℃澘閲岄潰鎶婇渶瑕佹敼鍙樼殑鍦版柟鐢ㄧ壒娈婄殑瀛楃浠f浛鈥曗€曞皢妯℃澘涓殑鍐呭鍙栧嚭鏉ュ瓨鏀惧埌涓€涓瓧绗︿覆涓紙杩欎釜瀛楃涓茬殑鍐呭 灏辨槸HTML浠g爜鍜屼笂闈㈡墍璇寸殑鐗规畩瀛楃浜嗭級鈥曗€曚娇鐢ㄥ嚱鏁板皢杩欎釜瀛楃涓查噷闈㈢殑鐗规畩瀛楃鐢ㄦ垜浠渶瑕佸湪椤甸潰涓婃樉绀虹殑鍐呭鏇挎崲鈥曗€曟妸鏇挎崲鍚庣殑瀛楃涓插啓鍒颁竴涓柊 鐨?htm椤甸潰閲岄潰鈥曗€曟垚鍔熶簡锛?/p>

 

鍔熻兘鐨勫疄鐜扮涓嶅紑PHP鍑芥暟鐨勫府蹇欍€傜煡閬撴暣浣撴€濊矾鍚庢渶閲嶈鐨勫氨鏄幓鎵嬪唽閲岄潰鎵剧浉鍏崇殑鍑芥暟浜嗐€?/p>

 

棣栧厛锛屾垜浠鎶婃ā鏉块噷闈㈢殑HTML浠g爜鍙栧嚭鏉ユ斁鍒颁竴涓彉閲忎腑鍘伙紝杩欎釜鍙橀噺鐨勫€煎氨鏄寘鍚獺TML鐨勫瓧绗︿覆浜嗐€傛垜浠彲浠ヤ娇鐢╯tring fread ( int handle, int length )鍑芥暟鏉ュ疄鐜帮紝浠旂粏涓€鐪嬮噷闈㈢殑鍙傛暟"handle"鏄竴涓枃浠舵寚閽堬紝杩欐剰鍛崇潃鎴戜滑寰楀厛鎶婃ā鏉挎枃浠舵墦寮€锛圥HP杩欎竴鐐圭浉褰撻夯鐑︼紝闅鹃亾瀹冨氨涓嶈兘寮勫緱涓€姝ュ埌浣?鍚楋紒锛侊紒锛夈€傚ソ锛屾垜浠户缁壘鑳芥妸鏂囦欢鎵撳紑鐨勫嚱鏁帮細resource fopen ( string filename, string mode [, bool use_include_path [, resource zcontext]] )锛屽湪杩欓噷鎴戜滑鍙浼犲叆鍓嶄袱涓弬鏁板氨鍙互浜嗭紝绗竴涓弬鏁板氨鏄枃浠跺悕瀛椾簡锛岃寰楄矾寰勪笉瑕佸紕閿欙紱绗簩涓弬鏁板缓璁娇鐢?rb"锛?r"浠h〃鍙鏂瑰紡鎵撳紑锛屽苟灏嗘枃 浠舵寚閽堟寚鍚戞枃浠跺ご锛?b" 鏄寚寮哄埗浣跨敤浜岃繘鍒舵ā寮忥紝鎵嬪唽涓缓璁細涓虹Щ妞嶆€ц€冭檻锛屽己鐑堝缓璁湪鐢?fopen() 鎵撳紑鏂囦欢鏃舵€绘槸浣跨敤 鈥榖鈥?鏍囪銆?/p>

鍦ㄨ繖涓€姝ユ垜浠殑浠g爜鍙互杩欐牱鍐欙細

 

CODE:[Copy to clipboard]<?php

$filemodel="template/it.php"; #妯℃澘鍦板潃

$file=fopen($filemodel,"rb"); #鎵撳紑妯℃澘锛屽緱鍒版枃浠舵寚閽?/p>

$temp=fread($file,filesize($filemodel)); #寰楀埌妯℃澘鏂囦欢html浠g爜

?>鎻愰啋涓€涓嬶細濡傛灉浣犲彧鏄兂灏嗕竴涓枃浠剁殑鍐呭璇诲叆鍒颁竴涓瓧绗︿覆涓紝鐢?file_get_contents()锛屽畠鐨勬€ц兘姣攆read()鐨勪唬鐮佸ソ寰楀(杩欐槸鎵嬪唽涓婄殑鍘熻瘽锛屼笉杩囪繖涓嚱鏁版槸鍦≒HP5涓敮鎸佺殑)銆?/p>

 

绗簩姝ワ紝浣跨敤str_replace()鍑芥暟灏嗗緱鍒扮殑鏂囦欢瀛楃鏇挎崲鐩稿叧鍐呭锛屾浛鎹㈢殑鏂规硶灏辨槸鎶婁粠鏁版嵁搴撲腑鍙栧嚭鐨勫唴瀹规垨閫氳繃琛ㄥ崟鐨勫緱鍒扮殑鏁版嵁鎶婃ā鏉夸腑鐨勭壒娈婂瓧绗︽浛鎹簡銆傝繖涓€姝ュ緢绠€鍗曪紝涔熻鍒氬紑濮嬫兂涓嶆槑鐧斤紝浣嗘槸涓€鐪嬩唬鐮佸氨涓€鐩簡鐒朵簡锛?/p>

 

CODE:[Copy to clipboard]<?php

$temp=str_replace("[title]",$title,$temp);

?>涓婇潰鐨?"[title]""灏辨槸妯℃澘鏂囦欢涓殑鐗规畩瀛楃锛堟槸[title],涓嶆槸"[title]"锛?"$title"灏辨槸鎴戜滑鎯冲湪椤甸潰涓婃樉绀虹殑鍐呭锛?$temp"灏辨槸妯℃澘鏂囦欢html浠g爜浜嗐€?/p>

 

濡傛灉杩橀渶瑕佹浛鎹紝鍒欑户缁娇鐢╯tr_replace()鍑芥暟灏卞彲浠ヤ簡锛屽锛?/p>

 

CODE:[Copy to clipboard]<?php

$temp=str_replace("[postTime]",$postTime,$temp);

$temp=str_replace("[content]",$content,$temp);

?>绗笁姝ワ紝涔熷氨鏄涓€姝ョ殑鍙嶆搷浣滀簡锛氳鎶婁箣鍓嶅鐞嗚繃鐨勬ā鏉垮瓧绗︿覆鍐欏叆鍙︿竴涓枃浠朵腑鍘伙紝鑰岃繖涓枃浠跺氨鏄垜浠渶缁堝彲浠ュ澶栨樉绀虹殑椤甸潰銆傜幇鍦ㄩ噸澶嶇被浼肩涓€姝ョ殑浜岄儴鏇诧細鎵撳紑鏂囦欢锛屽啓鍏ユ枃浠讹細

 

CODE:[Copy to clipboard]<?php

fwrite(fopen("$filename","wb"),$temp); #$filename鏄潤鎬侀〉闈㈢殑鏂囦欢鍚?/p>

?>fwrite鐨勪綔鐢ㄥ氨鏄妸瀛楃涓茬殑鍐呭鍐欏叆鏂囦欢涓幓浜嗐€?/p>

 

鍚屾牱锛屼篃鍙互浣跨敤file_put_contents鍑芥暟鍐欐枃浠讹紝浣嗚寰楁槸鍦≒HP5涓€?/p>

 

杩欐牱锛屾垜浠氨鍙互鐢ㄦā鏉跨敓鎴愰潤鎬侀〉闈簡銆?/p>

 

浜岋紟 鍒╃敤杈撳嚭鎺у埗鍑芥暟锛圤utput Control锛夌敓鎴愰潤鎬侀〉闈?/p>

 

杩欎釜涓庣敤妯℃澘鐢熸垚鐨勭浉姣旂浉瀵归珮绾т竴鐐癸紝浣嗕竴鏃︽槑鐧戒簡瀹冪殑瀹炵幇鎬濊矾锛屽嵈鏄畝鍗曟棤姣旓紝鎵€璋撲細鑰呬笉闅撅紝闅捐€呬笉浼氬ぇ姒傚氨鏄繖涔堜竴鍥炰簨鍚с€?/p>

 

杩欑鏂规硶姣旀ā鏉跨敓鎴愮殑鏂规硶搴旂敤闈㈡洿澶с€備娇鐢ㄦā鏉跨敓鎴愭柟娉曚竴鑸敤浜庡彂琛ㄦ垨淇敼鏂囩珷鏃朵娇鐢紝杩欐牱鐨勮瘽鏁版嵁搴撳彲浠ョ洿鎺ヤ粠琛ㄥ崟寰楀埌锛屽氨鏃犻』閫氳繃鏁版嵁搴撲簡銆傚綋濡傛灉闇€ 瑕佷粠鏁版嵁搴撳彇鍑烘暟鎹紝骞朵笖鏇挎崲鐨勪笢瑗挎瘮杈冨锛屾洿鎴栬€呬綘闇€瑕佺殑椤甸潰骞朵笉浠呬粎鏄€氳繃绠€鍗曠殑鏇挎崲灏辫兘寰楀埌鐨勶紝姣斿璇寸珯鐐圭殑棣栭〉銆傝繖鏃讹紝灏辨湁蹇呰鑰冭檻浣跨敤杈撳嚭鎺у埗 鍑芥暟浜嗐€?/p>

 

杈撳嚭鎺у埗鍑芥暟鐨勪綔鐢ㄦ槸璁剧疆缂撳啿鍖猴紝鍦ㄧ紦鍐插尯閲岄潰杈撳嚭鐨勫唴瀹瑰彲浠ヨ鑾峰緱銆傝幏寰楄緭鍑哄唴瀹规暣涓繃绋嬪彧闇€瑕佷娇鐢ㄤ笁涓嚱鏁颁究鍙互浜嗭細ob_start()銆乷b_get_contents()銆乷b_end_clean()

 

鏂规硶鎬濊矾濡備笅锛氳缃紦鍐插尯璧风偣锛堟垨璁剧疆杈撳嚭鍐呭鐨勮捣鐐癸級鈥曗€曢噴鏀惧唴瀹光€曗€曞彇寰楀唴瀹光€曗€曟竻绌虹紦鍐插尯鈥曗€曟妸鍙栧緱鐨勫唴瀹瑰啓濡傛枃浠躲€?/p>

 

鐩稿叧鍑芥暟璇存槑濡備笅锛?/p>

1銆乷b_start 锛氭墦寮€杈撳嚭缂撳啿鍖?/p>

鍑芥暟鏍煎紡锛歷oid ob_start(void)

璇存槑锛氬綋缂撳啿鍖烘縺娲绘椂锛屾墍鏈夋潵鑷狿HP绋嬪簭鐨勯潪鏂囦欢澶翠俊鎭潎涓嶄細鍙戦€侊紝鑰屾槸淇濆瓨鍦ㄥ唴閮ㄧ紦鍐插尯銆?/p>

涓轰簡杈撳嚭缂撳啿鍖虹殑鍐呭锛屽彲浠ヤ娇鐢╫b_end_flush()鎴杅lush()杈撳嚭缂撳啿鍖虹殑鍐呭銆?/p>

2 銆乷b_get_contents 锛氳繑鍥炲唴閮ㄧ紦鍐插尯鐨勫唴瀹广€?/p>

浣跨敤鏂规硶锛歴tring ob_get_contents(void)

璇存槑锛氳繖涓嚱鏁颁細杩斿洖褰撳墠缂撳啿鍖轰腑鐨勫唴瀹癸紝濡傛灉杈撳嚭缂撳啿鍖烘病鏈夋縺娲伙紝鍒欒繑鍥?FALSE 銆?/p>

3銆乷b_end_clean锛氬垹闄ゅ唴閮ㄧ紦鍐插尯鐨勫唴瀹癸紝骞朵笖鍏抽棴鍐呴儴缂撳啿鍖?/p>

浣跨敤鏂规硶锛歷oid ob_end_clean(void)

璇存槑锛氳繖涓嚱鏁颁笉浼氳緭鍑哄唴閮ㄧ紦鍐插尯鐨勫唴瀹硅€屾槸鎶婂畠鍒犻櫎锛?/p>

 

绮惧僵寮€濮嬩簡锛岀湅鐪嬫垜浠槸濡備綍鍒╃敤杈撳嚭缂撳啿鐢熸垚闈欐€侀〉闈㈢殑锛?/p>

 

鎴戜滑鐢ㄥ嚱鏁版潵瀹炵幇鍚э紒

 

CODE:[Copy to clipboard]<?php

#write by yayu

function createStaticPage($sourcePage,$objectPage)#鏉ユ簮鏂囦欢锛岀洰鏍囨枃浠?/p>

{

#寰楀埌涓や釜鍙傛暟锛屼竴涓槸鏉ユ簮鏂囦欢鍦板潃锛屼竴涓槸闇€瑕佺敓鎴愮殑闈欐€侀〉闈㈠湴鍧€

global $db; #鏁版嵁搴撹繛鎺ョ敤鐨勶紝鍦?sourcePage涓渶瑕佺敤鍒?/p>

 

ob_start(); #鎵撳紑缂撳啿鍖猴紝鐩稿綋浜庡仛浜嗕竴涓敤鏉ュ瓨鏀句笢瑗跨殑绠卞瓙

 

include $sourcePage; #鍦ㄧ紦鍐插尯涓噴鏀鹃〉闈紝浠庤繖涓唬鐮佷腑搴旇鍙互鏄庣櫧涓€鐐癸細閭e氨鏄?sourcePage椤甸潰鍗曠嫭鏌ョ湅鐨勬椂鍊欙紝瀹冩槸鍙互鏄剧ず鐨勶紒杩欐槸鍏抽敭涔嬫墍鍦紝濡傛灉鍚庨潰涓嶅姞ob_end_clean()鍑芥暟锛岄偅鍦ㄦ墽琛岀▼搴忕殑鏃跺€欎綘鐪嬭$sourcePage椤甸潰鐨勫唴瀹广€?/p>

 

$cons=ob_get_contents(); #寰楀埌缂撳啿鍖轰腑鐨勫唴瀹癸紝杩欓噷鐨勫唴瀹瑰氨鏄疕TML浠g爜锛佽繖鐩稿綋浜庢妸绠卞瓙閲岄潰鐨勪笢瑗胯浆缁欎簡涓€涓汉锛?/p>

 

ob_end_clean(); #娓呴櫎缂撳啿鍖虹殑鍐呭锛屾妸绠卞瓙閲岄潰鐨勪笢瑗胯浆缁欎粬浜哄悗锛屾墦鎵崼鐢燂紝涓嶆墦鎵崼鐢熺殑鍚庢灉鏄浠栦汉鍙互鐪嬭绠卞瓙鐨勪笢瑗匡紝涔熷嵆鍙互鐪嬭$sourcePage椤甸潰鐨勫唴瀹?/p>

 

$fp=fopen($objectPage,"wb") or die("闈欐€佺敓鎴愭椂鎵撳紑鏂囦欢".$objectPage."鏃跺嚭閿?);

 

fwrite($fp,$cons); #鎶奌TML浠g爜鍐欏叆闈欐€佹枃浠朵腑锛?/p>

 

fclose($fp);

 

return true;

}

?>鎬荤粨锛?/p>

1锛?涓ょ鏂规硶閮芥湁鎶婂唴瀹瑰啓鍏ヤ綘瑕佺敓鎴愮殑闈欐€侀〉闈腑鐨勪竴姝ャ€?/p>

2锛?褰撳彲浠ヤ娇鐢ㄧ涓€绉嶆柟娉曟椂灏变娇鐢ㄧ涓€绉嶆柟娉曪紝鍥犱负绗簩绉嶆柟娉曡閫氳繃鏁版嵁搴撹皟鍐呭骞舵樉绀猴紙涔熷彲浠ヨ鏄殣钘忎簡鏄剧ず鐨勫唴瀹癸紝浣嗕簨瀹炰笂$sourcePage閲岀殑绋嬪簭鏄墽琛岀殑锛夌殑杩囩▼銆?/p>

3锛?鍏蜂綋鎯呭喌鍏朵粬鍒嗘瀽锛屽湪浣跨敤妯℃澘鐢熸垚鏃剁敱浜庡彲鑳界洿鎺ヤ娇鐢ㄨ〃鍗曟彁浜ょ殑鍐呭锛屾墍浠ラ渶瑕佽繃婊や箣绫荤殑妫€鏌ャ€?/p>

*******************************************************

 

PHP鐢熸垚闈欐€侀〉闈?/p>

銆€銆€鐪嬪埌寰堝鏈嬪弸鍦ㄥ悇涓湴鏂瑰彂甯栭棶PHP鐢熸垚闈欐€佹枃绔犵郴缁熺殑鏂规硶锛屼互鍓嶆浘鍋氳繃杩欐牱涓€涓郴缁燂紝閬傝皥浜涚湅娉曪紝浠ヤ緵鍚勪綅鍙傝€冦€傚ソ浜嗭紝鎴戜滑鍏堝洖椤句竴浜涘熀鏈殑姒傚康銆?/p>

 

銆€銆€涓€锛孭HP鑴氭湰涓庡姩鎬侀〉闈€?/p>

 

銆€銆€PHP鑴氭湰鏄竴绉嶆湇鍔″櫒绔剼鏈▼搴忥紝鍙€氳繃宓屽叆绛夋柟娉曚笌HTML鏂囦欢娣峰悎锛屼篃鍙互绫伙紝鍑芥暟灏佽绛夊舰寮忥紝浠ユā鏉跨殑鏂瑰紡瀵圭敤鎴疯姹傝繘琛屽鐞嗐€傛棤璁轰互浣曠鏂瑰紡锛屽畠鐨勫熀鏈師鐞嗘槸杩欐牱鐨勩€傜敱瀹㈡埛绔彁鍑鸿姹傦紝璇锋眰鏌愪竴椤甸潰銆€----->銆€WEB鏈嶅姟鍣ㄥ紩鍏ユ寚瀹氱浉搴旇剼鏈繘琛屽鐞嗐€€----->銆€鑴氭湰琚浇鍏ユ湇鍔″櫒銆€----->銆€鐢辨湇鍔″櫒鎸囧畾鐨凱HP瑙f瀽鍣ㄥ鑴氭湰杩涜瑙f瀽褰㈡垚HTML璇█褰㈠紡銆€---->銆€灏嗚В鏋愬悗鐨凥TML璇彞浠ュ寘鐨勬柟寮忎紶鍥炵粰娴忚鍣ㄣ€傜敱姝や笉闅剧湅鍑猴紝鍦ㄩ〉闈㈠彂閫佸埌娴忚鍣ㄥ悗锛孭HP灏变笉瀛樺湪浜嗭紝宸茶杞寲瑙f瀽涓篐TML璇彞銆傚鎴疯姹備负涓€鍔ㄦ€佹枃浠讹紝浜嬪疄涓婂苟娌℃湁鐪熸鐨勬枃浠跺瓨鍦ㄥ湪閭i噷锛屾槸PHP瑙f瀽鑰屾垚鐩稿搴旂殑椤甸潰锛岀劧鍚庡彂閫佸洖娴忚鍣ㄣ€傝繖绉嶉〉闈㈠鐞嗘柟寮忚绉颁负"鍔ㄦ€侀〉闈?銆?/p>

 

銆€銆€浜岋紝闈欐€侀〉闈€?/p>

 

銆€銆€闈欐€侀〉闈㈡槸鎸囧湪鏈嶅姟鍣ㄧ纭疄瀛樺湪鐨勪粎鍚獺TML浠ュ強JS锛孋SS绛夊鎴风杩愯鑴氭湰鐨勯〉闈€傚畠鐨勫鐞嗘柟寮忔槸銆傜敱瀹㈡埛绔彁鍑鸿姹傦紝璇锋眰鏌愪竴椤甸潰銆€---->銆€WEB鏈嶅姟鍣ㄧ‘璁ゅ苟杞藉叆鏌愪竴椤甸潰銆€---->銆€WEB鏈嶅姟鍣ㄥ皢璇ラ〉闈互鍖呯殑褰㈠紡浼犻€掑洖娴忚鍣ㄣ€傜敱杩欎竴杩囩▼锛屾垜浠姣斾竴涓嬪姩鎬侀〉闈紝鍗冲彲鏂圭幇銆傚姩鎬侀〉闈㈤渶鐢盬EB鏈嶅姟鍣ㄧ殑PHP瑙f瀽鍣ㄨ繘琛岃В鏋愶紝鑰屼笖閫氬父杩橀渶杩炴帴鏁版嵁搴擄紝杩涜鏁版嵁搴撳瓨鍙栨搷浣滐紝鐒跺悗鎵嶈兘褰㈡垚HTML璇█淇℃伅鍖咃紱鑰岄潤鎬侀〉闈紝鏃犻』瑙f瀽锛屾棤椤昏繛鎺ユ暟鎹簱锛岀洿鎺ュ彂閫侊紝鍙ぇ澶у噺杞绘湇鍔″櫒鍘嬪姏锛屾彁楂樻湇鍔″櫒璐熻浇鑳藉姏锛屽ぇ骞呮彁渚涢〉闈㈡墦寮€閫熷害鍜岀綉绔欐暣浣撴墦寮€閫熷害銆備絾鍏剁己鐐规槸锛屼笉鑳藉姩鎬佸湴瀵硅姹傝繘琛屽鐞嗭紝鏈嶅姟鍣ㄤ笂蹇呴』纭疄瀛樺湪璇ユ枃浠躲€?/p>

 

銆€銆€涓夛紝妯℃澘鍙婃ā鏉胯В鏋愩€?/p>

 

銆€銆€妯℃澘鍗冲皻鏈~鍏呭唴瀹筯tml鏂囦欢銆備緥濡傦細

 

銆€temp.html

 

<HTML>

銆€ <TITLE>{ title}</TITLE>

銆€ <BODY>

銆€銆€銆€this is a { file} file鈥榮 templets

銆€ </BODY>

</HTML>

 

PHP澶勭悊锛?/p>

 

銆€templetest.php

 

<?php

銆€ 锛則itle = "涔濈綉浜掕仈娴嬭瘯妯℃澘";

銆€ 锛刦ile銆€ = "Webjx銆€test templet,<br>author锛?;

 

銆€锛刦p= fopen ("temp.html","r");

銆€ 锛刢ontent銆€= fread (锛刦p,filesize ("temp.html"));

銆€ 锛刢ontent .= str_replace ("{ file}",锛刦ile,锛刢ontent);

銆€ 锛刢ontent .= str_replace ("{ title}",锛則itle,锛刢ontent);

 

銆€ echo 锛刢ontent;

?>

 

 

銆€銆€妯℃澘瑙f瀽澶勭悊锛屽嵆灏嗙粡PHP鑴氭湰瑙f瀽澶勭悊鍚庡緱鍑虹殑缁撴灉濉厖(content)杩涙ā鏉跨殑澶勭悊杩囩▼銆傞€氬父鍊熷姪浜庢ā鏉跨被銆傜洰鍓嶈緝娴佽鐨勬ā鏉胯В鏋愮被鏈塸hplib锛宻marty锛宖astsmarty绛夌瓑銆傛ā鏉胯В鏋愬鐞嗙殑鍘熺悊閫氬父涓烘浛鎹€備篃鏈変簺绋嬪簭鍛樹範鎯皢鍒ゆ柇锛屽惊鐜瓑澶勭悊鏀捐繘妯℃澘鏂囦欢涓紝鐢ㄨВ鏋愮被澶勭悊锛屽吀鍨嬪簲鐢ㄤ负block姒傚康锛岀畝鍗曟潵璇村嵆涓轰竴涓惊鐜鐞嗐€傜敱PHP鑴氭湰鎸囧畾寰幆娆℃暟锛屽浣曞惊鐜唬鍏ョ瓑锛屽啀鐢辨ā鏉胯В鏋愮被鍏蜂綋瀹炴柦杩欎簺鎿嶄綔銆?/p>

 

銆€銆€濂戒簡锛屽姣旇繃闈欐€侀〉闈笌鍔ㄦ€侀〉闈㈠悇鑷殑浼樺姡锛岀幇鍦ㄦ垜浠氨鏉ヨ璇达紝濡備綍鐢≒HP鐢熸垚闈欐€佹枃浠躲€?/p>

 

銆€銆€PHP鐢熸垚闈欐€侀〉闈㈠苟涓嶆槸鎸嘝HP鐨勫姩鎬佽В鏋愶紝杈撳嚭HTML椤甸潰锛岃€屾槸鎸囩敤PHP鍒涘缓HTML椤甸潰銆傚悓鏃跺洜涓篐TML鐨勪笉鍙啓鎬э紝鎴戜滑鍒涘缓鐨凥TML鑻ユ湁淇敼锛屽垯闇€鍒犳帀閲嶆柊鐢熸垚鍗冲彲銆?褰撶劧浣犱篃鍙互閫夋嫨鐢ㄦ鍒欒繘琛屼慨鏀癸紝浣嗕釜浜鸿涓洪偅鏍峰仛鍊掍笉濡傚垹鎺夐噸鏂扮敓鎴愭潵寰楀揩鎹凤紝鏈変簺寰椾笉鍋垮け銆?

 

銆€銆€瑷€褰掓浼犮€傜敤杩嘝HP鏂囦欢鎿嶄綔鍑芥暟鐨凱HP FANS鐭ラ亾锛孭HP涓湁涓€涓枃浠舵搷浣滃嚱鏁癴open锛屽嵆鎵撳紑鏂囦欢銆傝嫢鏂囦欢涓嶅瓨鍦紝鍒欏皾璇曞垱寤恒€傝繖鍗虫槸PHP鍙互鐢ㄦ潵鍒涘缓HTML鏂囦欢鐨勭悊璁哄熀纭€銆傚彧瑕佺敤鏉ュ瓨鏀綡TML鏂囦欢鐨勬枃浠跺す鏈夊啓鏉冮檺(鍗虫潈闄愬畾涔?777)锛屽嵆鍙垱寤烘枃浠躲€傦紙閽堝UNIX绯荤粺鑰岃█锛學in绯荤粺鏃犻』鑰冭檻銆傦級浠嶄互涓婁緥涓轰緥锛岃嫢鎴戜滑淇敼鏈€鍚庝竴鍙ワ紝骞舵寚瀹氬湪test鐩綍涓嬬敓鎴愪竴涓悕涓簍est.html鐨勯潤鎬佹枃浠讹細

 

<?php

銆€ 锛則itle = "涔濈綉浜掕仈娴嬭瘯妯℃澘";

銆€ 锛刦ile銆€ = "Webjx銆€test templet,<br>author锛?;

 

銆€锛刦p銆€銆€銆€銆€銆€= fopen ("temp.html","r");

銆€ 锛刢ontent銆€= fread (锛刦p,filesize ("temp.html"));

銆€ 锛刢ontent .= str_replace ("{ file}",锛刦ile,锛刢ontent);

銆€ 锛刢ontent .= str_replace ("{ title}",锛則itle,锛刢ontent);

 

銆€ // echo 锛刢ontent;

銆€  

銆€ 锛刦ilename = "test/test.html";

銆€ 锛刪andle銆€銆€= fopen (锛刦ilename,"w"); //鎵撳紑鏂囦欢鎸囬拡锛屽垱寤烘枃浠?/p>

銆€ /*

銆€妫€鏌ユ枃浠舵槸鍚﹁鍒涘缓涓斿彲鍐?/p>

銆€ */

銆€ if (!is_writable (锛刦ilename)){

銆€銆€銆€die ("鏂囦欢锛?.锛刦ilename."涓嶅彲鍐欙紝璇锋鏌ュ叾灞炴€у悗閲嶈瘯锛?);

銆€ }

銆€ if (!fwrite (锛刪andle,锛刢ontent)){ 銆€//灏嗕俊鎭啓鍏ユ枃浠?/p>

銆€銆€銆€die ("鐢熸垚鏂囦欢".锛刦ilename."澶辫触锛?);

銆€ }

銆€ fclose (锛刪andle); //鍏抽棴鎸囬拡

銆€  

銆€ die ("鍒涘缓鏂囦欢".锛刦ilename."鎴愬姛锛?);

?>

 

銆€銆€瀹為檯搴旂敤涓父瑙侀棶棰樿В鍐虫柟妗堝弬鑰冿細

 

銆€銆€涓€锛屾枃绔犲垪琛ㄩ棶棰橈細

 

銆€銆€鍦ㄦ暟鎹簱涓垱寤哄瓧娈碉紝璁板綍鏂囦欢鍚嶏紝姣忕敓鎴愪竴涓枃浠讹紝灏嗚嚜鍔ㄧ敓鎴愮殑鏂囦欢鍚嶅瓨鍏ユ暟鎹簱锛屽浜庢帹鑽愭枃绔狅紝鍙渶鎸囧悜瀛樻斁闈欐€佹枃浠剁殑鎸囧畾鏂囦欢澶逛腑鐨勮椤甸潰鍗冲彲銆傚埄鐢≒HP鎿嶄綔澶勭悊鏂囩珷鍒楄〃锛屽瓨涓哄瓧绗︿覆锛岀敓鎴愰〉闈㈡椂鏇挎崲姝ゅ瓧绗︿覆鍗冲彲銆傚锛屽湪椤甸潰涓斁缃枃绔犲垪琛ㄧ殑琛ㄦ牸鍔犲叆鏍囪{ articletable}锛岃€屽湪PHP澶勭悊鏂囦欢涓細

 

<?php

銆€ 锛則itle = "涔濈綉浜掕仈娴嬭瘯妯℃澘";

銆€ 锛刦ile銆€ = "Webjx銆€test templet,<br>author锛?;

 

銆€锛刦p銆€銆€銆€銆€銆€= fopen ("temp.html","r");

銆€ 锛刢ontent銆€= fread (锛刦p,filesize ("temp.html"));

銆€ 锛刢ontent .= str_replace ("{ file}",锛刦ile,锛刢ontent);

銆€ 锛刢ontent .= str_replace ("{ title}",锛則itle,锛刢ontent);

銆€  

銆€ //銆€鐢熸垚鍒楄〃寮€濮?/p>

銆€ 锛刲ist = 鈥樷€?

銆€ 锛剆ql = "select id, title,filename from article";

銆€ 锛剄uery = mysql_query (锛剆ql);

銆€ while (锛剅esult = mysql_fetch_array(锛剄uery)){

銆€銆€銆€锛刲ist .= 鈥?lt;a href=鈥?锛剅oot.锛剅esult[鈥榝ilename鈥榏.鈥?target=_blank>鈥?锛剅esult[鈥榯itle鈥榏.鈥?lt;/a><br>鈥?

銆€ }

銆€ 锛刢ontent .= str_replace ("{ articletable}",锛刲ist,锛刢ontent);

銆€  

銆€ //鐢熸垚鍒楄〃缁撴潫

銆€ // echo 锛刢ontent;

銆€  

銆€ 锛刦ilename = "test/test.html";

銆€ 锛刪andle銆€銆€= fopen (锛刦ilename,"w"); //鎵撳紑鏂囦欢鎸囬拡锛屽垱寤烘枃浠?/p>

銆€ /*

銆€妫€鏌ユ枃浠舵槸鍚﹁鍒涘缓涓斿彲鍐?/p>

銆€ */

銆€ if (!is_writable (锛刦ilename)){

銆€銆€銆€die ("鏂囦欢锛?.锛刦ilename."涓嶅彲鍐欙紝璇锋鏌ュ叾灞炴€у悗閲嶈瘯锛?);

銆€ }

銆€ if (!fwrite (锛刪andle,锛刢ontent)){ 銆€//灏嗕俊鎭啓鍏ユ枃浠?/p>

銆€銆€銆€die ("鐢熸垚鏂囦欢".锛刦ilename."澶辫触锛?);

銆€ }

銆€ fclose (锛刪andle); //鍏抽棴鎸囬拡

銆€  

銆€ die ("鍒涘缓鏂囦欢".锛刦ilename."鎴愬姛锛?);

?>

 

銆€銆€浜岋紝鍒嗛〉闂銆?/p>

 

銆€銆€濡傛垜浠寚瀹氬垎椤垫椂锛屾瘡椤?0绡囥€傛煇瀛愰閬撳垪琛ㄥ唴鏂囩珷缁忔暟鎹簱鏌ヨ涓?5鏉★紝鍒欙紝棣栧厛鎴戜滑閫氳繃鏌ヨ寰楀埌濡備笅鍙傛暟锛?锛屾€婚〉鏁帮紱2锛屾瘡椤电瘒鏁般€傜浜屾锛宖or (锛刬 = 0; 锛刬 < allpages; 锛刬++)锛岄〉闈㈠厓绱犺幏鍙栵紝鍒嗘瀽锛屾枃绔犵敓鎴愶紝閮藉湪姝ゅ惊鐜腑鎵ц銆備笉鍚岀殑鏄紝die ("鍒涘缓鏂囦欢".锛刦ilename."鎴愬姛锛?;杩欏彞鍘绘帀锛屾斁鍒板惊鐜悗鐨勬樉绀猴紝鍥犱负璇ヨ鍙ュ皢涓绋嬪簭鎵ц銆備緥锛?/p>

 

<?php

锛刦p=fopen ("temp.html","r");

銆€ 锛刢ontent銆€= fread (锛刦p,filesize ("temp.html"));

銆€ 锛刼nepage銆€= 鈥?0鈥?

銆€ 锛剆ql銆€銆€銆€銆€銆€= "select id from article where channel=鈥橈紕channelid鈥?;

銆€ 锛剄uery銆€銆€銆€= mysql_query (锛剆ql);

銆€ 锛刵um銆€銆€銆€銆€= mysql_num_rows (锛剄uery);

銆€ 锛刟llpages銆€ = ceil (锛刵um / 锛刼nepage);

 

銆€ for (锛刬 = 0;锛刬<锛刟llpages; 锛刬++){

銆€銆€銆€if (锛刬 == 0){

銆€銆€銆€銆€ 锛刬ndexpath = "index.html";

銆€銆€銆€} else {

銆€銆€銆€銆€ 锛刬ndexpath = "index_".锛刬."html";

銆€銆€銆€}

銆€銆€銆€锛剆tart = 锛刬 * 锛刼nepage;

銆€銆€銆€锛刲ist銆€銆€= 鈥樷€?

銆€銆€銆€锛剆ql_for_page = "select name, filename,title from article where channel=鈥橈紕channelid鈥?limit 锛剆tart,锛刼nepage";

銆€銆€銆€锛剄uery_for_page = mysql_query (锛剆ql_for_page);

銆€銆€銆€while (锛剅esult = 锛剄uery_for_page){

銆€銆€銆€銆€ 锛刲ist .= 鈥?lt;a href=鈥?锛剅oot.锛剅esult[鈥榝ilename鈥榏.鈥?target=_blank>鈥?锛則itle.鈥?lt;/a><br>鈥?

銆€銆€銆€}

銆€銆€銆€  

銆€銆€銆€锛刢ontent = str_replace ("{ articletable}",锛刲ist,锛刢ontent);

 

銆€銆€銆€if (is_file (锛刬ndexpath)){

銆€銆€銆€銆€ @unlink (锛刬ndexpath); //鑻ユ枃浠跺凡瀛樺湪锛屽垯鍒犻櫎

銆€銆€銆€}

 

銆€銆€銆€锛刪andle銆€銆€= fopen (锛刬ndexpath,"w"); //鎵撳紑鏂囦欢鎸囬拡锛屽垱寤烘枃浠?/p>

銆€銆€銆€/*

銆€銆€ 妫€鏌ユ枃浠舵槸鍚﹁鍒涘缓涓斿彲鍐?/p>

銆€銆€銆€*/

銆€銆€銆€if (!is_writable (锛刬ndexpath)){

銆€銆€銆€銆€ echo "鏂囦欢锛?.锛刬ndexpath."涓嶅彲鍐欙紝璇锋鏌ュ叾灞炴€у悗閲嶈瘯锛?; //淇敼涓篹cho

銆€銆€銆€}

銆€銆€銆€if (!fwrite (锛刪andle,锛刢ontent)){ 銆€//灏嗕俊鎭啓鍏ユ枃浠?/p>

銆€銆€銆€銆€ echo "鐢熸垚鏂囦欢".锛刬ndexpath."澶辫触锛?; //淇敼涓篹cho

銆€銆€銆€}

銆€銆€銆€fclose (锛刪andle); //鍏抽棴鎸囬拡

銆€ }

 

銆€ fclose (锛刦p);

銆€ die ("鐢熸垚鍒嗛〉鏂囦欢瀹屾垚锛屽鐢熸垚涓嶅畬鍏紝璇锋鏌ユ枃浠舵潈闄愮郴缁熷悗閲嶆柊鐢熸垚锛?);

 

?>

 

銆€銆€澶ц嚧鎬濊矾濡傛锛屽叾涓鍏跺畠鏁版嵁鐢熸垚锛屾暟鎹緭鍏ヨ緭鍑烘鏌ワ紝鍒嗛〉鍐呭鎸囧悜绛夊彲閰屾儏鍦ㄩ〉闈腑鍔犲叆銆?/p>

 

銆€銆€鍦ㄥ疄闄呮枃绔犵郴缁熷鐞嗚繃绋嬪綋涓紝杩樻湁璁稿闂鏈夊緟鑰冭檻锛屼笌鍔ㄦ€侀〉闈笉鍚屼箣澶勶紝闇€娉ㄦ剰鐨勫湴鏂硅繕鏈夊緢澶氥€備絾澶ц嚧鎬濊矾鍗虫槸濡傛锛屽叾瀹冩柟闈㈠彲涓句竴鍙嶄笁鑰屽緱銆?/p>

 

**********************************************************

 

鐩墠缃戠粶涓婂ソ澶氱綉绔欑殑鏂伴椈鍙戝竷绯荤粺閮介噰鐢ㄤ簡鍔ㄦ€佹湇鍔″櫒鎶€鏈敓鎴愰潤鎬丠TML鐨勫仛娉曪紝杩欐牱鍋氱殑濂藉鏄細涓€鏄兘鍑忚交鍏舵湇鍔″櫒鐨勮礋鎷咃紝浜屾槸鍥犱负鐢熸垚浜咹TML闈欐€侀〉闈紝鎵€浠ュ叾缃戠珯琚悳绱㈠紩鎿庢悳绱㈠埌鐨勬満鐜囨洿澶т竴浜涖€傜瑪鑰呯殑缃戠珯鏇剧粡浣跨敤PHP杩欎竴鍔ㄦ€佹妧鏈潵鏋勫缓鏂伴椈鍙戝竷绯荤粺锛屽叾鍘熺悊涔熷氨鏄簲鐢ㄤ簡PHP鐢熸垚HTML闈欐€侀〉闈㈢殑鎶€鏈紝鐩稿叧骞冲彴鏄?Windows XP Sp2+php4.32+mysql锛屽洜姝わ紝鍦ㄨ繖閲岋紝鎯崇畝鍗曞湴璋堜竴涓嬭繖绉嶅仛娉曠殑鎬濊矾銆傝繖绡囨枃绔犻€傚悎浜庡PHP+MYSQL鏁版嵁搴撴搷浣滐紝SQL璇彞浠ュ強缃戦〉璁捐鏈夌偣鍩虹鐨勬湅鍙嬶紝濡傛灉鎮ㄦ槸涓€涓粠澶村紑濮嬪鐨勬湅鍙嬶紝閭d箞璇峰厛鎵撳ソ鍩虹鍚э紒鍒拌繖閲屽氨涓嶇敤寰€涓嬬湅浜嗐€傚鏋滄偍閮界鍚堜笂杩版潯浠剁殑璇濓紝閭d箞鎭枩鎮紝璇锋帴鐫€寰€涓嬬湅銆備絾鏄紝鍦ㄥ叿浣撳姩鎵嬫瀯寤轰箣鍓嶏紝鎮ㄨ繕瑕佸仛濂戒互涓嬪嚑鐐瑰噯澶囧伐浣溿€?/p>

涓€銆?鍏峰鏈湴璋冭瘯PHP鐨勫姛鑳?/p>

 

鍦╓INDOWS XP鎿嶄綔绯荤粺涓嬶紝绗旇€呭缓璁綘鍙互鍒扮綉涓婁笅杞戒竴涓狿HP+MYSQL+APACHE鐨勬湇鍔″櫒濂楄锛屽鍗庡啗杞欢鍥紝鍘婚偅閲屾悳绱竴涓嬪氨鍙互涓嬭浇鍒般€備笅杞藉畬鍚庨粯璁ゅ畨瑁呭嵆鍙紝杩欐牱鎮ㄥ氨鍏峰浜嗗湪鏈湴娴嬭瘯PHP鐨勫姛鑳戒簡锛岀渷鍘讳簡寰堝鎵嬪姩閰嶇疆鐨勯夯鐑︼紝鎬庝箞鏍凤紝绠€鍗曞惂锛孫K锛岃繖浠呬粎鍙槸绗竴姝ャ€?/p>

 

浜屻€?鏋勬€濇柊闂诲彂甯冪郴缁熸墍鍏峰鐨勫姛鑳?/p>

 

棣栭〉鐨勬柊闂诲彂甯冨線寰€鏄€氳繃鍚庡彴鏇存柊鐨勶紝鍚庡彴鐨勬洿鏂版棤闈炴槸鐢辨坊鍔犮€佺紪杈戙€佸垹闄ゆ暟鎹瓑鍩烘湰鐨勫姛鑳芥墍瀹炵幇鐨勩€傚湪杩欓噷锛屼綘鍙互浣跨敤缃戦〉璁捐杞欢鏉ユ瀯寤轰綘鐨勬兂瑕佺殑鍚庡彴鐣岄潰锛屽叾鍔熻兘鐨勫疄鐜板綋鐒舵槸瑕佺敤鍒癙HP鍠姐€傝繖涓€姝ュ缓璁偍鍏堟兂濂芥柊闂诲彂甯冪郴缁熻鏈夌殑鍔熻兘銆傚湪杩欓噷锛屽浣曠敤PHP娣诲姞銆佺紪杈戙€佸垹闄ゆ暟鎹氨涓嶅啀閲嶅锛屽洜涓洪噸鐐规槸濡備綍鍦ㄨ繖鍩虹涓婄敓鎴愰潤鎬佹妧鏈€?/p>

 

涓夈€?PHP鐢熸垚HTML鐨勬妧鏈師鐞嗐€?/p>

 

鍝堝搱銆傝垂璇濊浜嗛偅涔堝锛岀粓浜庡埌浜嗚璁茬殑鍦版柟浜嗐€傚叾瀹烇紝杩欎竴鍘熺悊骞朵笉澶嶆潅锛岀患鍚堝湴鏉ヨ鐨勮瘽锛屽簲璇ユ槸PHP涓竴涓浛鎹㈡暟鎹娉曠殑搴旂敤銆侽K锛岃涓€涓畝鍗曡寖渚嬪惂锛屼竴姝ヤ竴姝ュ湴鍒嗘瀽锛佺浉淇¤仾鏄庣殑浣犺兘鐪嬪緱鏄庣櫧鐨勫挴锛屼粩缁嗙湅濂芥瘡涓€姝ュ嵆鍙紝鍦ㄨ繖閲岋紝鍙槸寮曞澶у濡備綍鍋氳€屽凡锛屽叿浣撶殑鍙互瀹炶返涓€涓嬶紒

 

锛?锛夊湪MYSQL閲屾柊寤轰竴鏁版嵁搴擄紝鍛藉悕涓?database 锛堝彲鑷畾涔夛級锛屾柊寤轰竴琛紝鍛藉悕涓?news锛堝洜涓烘槸鏂伴椈鍙戝竷鍢涳紝鍙栦釜濂借鐨勫悕瀛楀嵆鍙紝鍙嚜瀹氫箟锛夛紝鐒跺悗寤虹珛杩欏嚑涓瓧娈靛悕锛?/p>

id (鑷姩閫掑锛岃繖鏄叧閿紝绫诲瀷锛欼NT)

title (椤惧悕鎬濅箟锛屾柊闂绘爣棰橈紝绫诲瀷鍙彇 TEXT)

content (鏂伴椈鍐呭锛岀被鍨嬪彲鍙?TEXT)

path (HTML鏂囦欢璺緞锛岀被鍨嬪彲鍙?TEXT)

 

锛?锛夊缓绔?conn.php

杩欐槸杩炴帴鏁版嵁搴撶殑PHP鏂囦欢锛屼綘鍙互鎶婅繛鎺ユ暟鎹殑璇彞鍗曠嫭鏀惧湪杩欎竴鏂囦欢閲岋紝浠ュ悗澶氫釜闇€瑕佽繛鎺ユ暟鎹簱鐨勬枃浠剁洿鎺ュ紩鐢ㄨ繖涓枃浠跺嵆鍙€?/p>

 

锛?锛夎璁℃坊鍔犳柊闂荤殑琛ㄦ牸 add.form 绠€鍗曠殑婧愪唬鐮佸涓?

<form method="post" action="add.php"> //鎻愪氦鑷?add.php

鏂伴椈鏍囬:<input type="text" name="title" size="20"><br>

鏂伴椈鍐呭:<textarea name="content" cols="10" rows="25"></textarea><br>

<input type="submit" name="鎻愪氦">

</form>

 

锛?锛夊缓绔嬩竴涓?HTML 鐨勬ā鏉?鍙﹀瓨涓簃odel.htm,鍜?add.php鍙互鍦ㄥ悓涓€鐩綍涓嬨€?/p>

绀轰緥婧愪唬鐮?

<html>

<body>

姝ゆ柊闂荤殑鏍囬:{title}

姝ゆ柊闂荤殑鍐呭:{content}

</body>

</html>

{ }澶ф嫭鍙峰唴鐨勫唴瀹瑰嵆鏄琚浛鎹㈢殑鍐呭锛屾暣涓潤鎬佹ā鏉跨殑璁捐鍙互鏍规嵁鑷繁鐨勬€濊矾锛屼絾{ }鍐呰鏇挎崲鐨勫唴瀹瑰繀椤诲寘鍚湪鍐咃紝濡備笂闈㈢殑{title}锛寋content}锛涘挃鍜攡绠€鍗曞湴璇达紝璁捐濂戒竴涓緢濂界湅鐨勬柊闂绘ā鏉垮悗锛屾妸瑕佽鏇挎崲鐨勫{title},{content}绛夋爣璁版斁鍒伴渶瑕佺殑鍦版柟灏卞彲浠ヤ簡鎾掋€?/p>

 

锛?锛夎瑙?add.php 婧愮爜

<?php

require_once("conn.php")锛?//寮曠敤conn.php锛岃繛鎺ユ暟鎹簱

$title=$_POST["title"];

$content=$_POST["content"]; //鑾峰緱琛ㄥ崟鍙橀噺

 

//浠ヤ笅寤虹珛涓€鏂囨湰鏂囨。锛屽叾鍊艰嚜鍔ㄨ鏁?/p>

$countfile="count.txt";

if(!file_exists($countfile))

{

fopen($countfile,"w"); //濡傛灉姝ゆ枃浠朵笉瀛樺湪锛屽垯鑷姩寤虹珛涓€涓?/p>

}

$fp=fopen($countfile,"r");

$num=fgets($fp,20);

$num=$num+1; //姣忔鍏跺€艰嚜鍔ㄥ姞涓€

fclose($fp);

$fp=fopen($countfile,"w");

fwrite($fp,$num); //鏇存柊鍏跺€?/p>

fclose($fp);

 

 

//鍒╃敤涓婇潰鑷姩璁℃暟鐨勫€艰幏寰桯TML鐨勮矾寰?path

$houzui=".html";

$path=$num.$houzui;

//杩欐牱褰㈡垚鐨勮矾寰勬槸鑷姩澧為暱鐨勶紝濡?.html,2.html,3.html鈥︹€︹€?娣诲姞涓€鏉℃柊闂讳究鑷姩鍔犱笂1

 

//浠ヤ笅鐢⊿QL璇彞娣诲姞鏁版嵁鑷宠〃 news

$sql="insert into news (title,content,path) values (鈥?.$title."鈥?鈥?.$content."鈥?鈥?.$path."鈥?";

$query=mysql_query($sql);

 

//浠ヤ笅涓哄叧閿箣澶勶紝鎶婁粠琛ㄥ崟鑾峰緱鐨勬暟鎹浛鎹㈡ā鏉夸腑鐨剓title},{content}鏍囪 $fp=fopen("model.htm","r") //鍙鎵撳紑妯℃澘

$str=fread($fp,filesize("mode.htm"));//璇诲彇妯℃澘涓唴瀹?/p>

$str=str_replace("{title}",$title,$str);

$str=str_replace("{content}",$content,$str);//鏇挎崲鍐呭

fclose($fp);

 

$handle=fopen($path,"w"); //鍐欏叆鏂瑰紡鎵撳紑鏂伴椈璺緞

fwrite($handle,$str); //鎶婂垰鎵嶆浛鎹㈢殑鍐呭鍐欒繘鐢熸垚鐨凥TML鏂囦欢

fclose($handle);

 

 

//鏀跺熬宸ヤ綔:

echo "<a href=$path target=_blank>鏌ョ湅鍒氭墠娣诲姞鐨勬柊闂?lt;/a>";

 

OK,鏁翠釜鐢熸垚HTML鐨勭ず渚嬫簮鐮佸氨鍒拌繖閲岋紝鍏跺叧閿槸鐢ㄤ簡鏇挎崲鐨勬柟娉曘€?/p>

$str=str_replace("{琚浛鎹㈢殑鍐呭}",$鏇挎崲鐨勫唴瀹?$str);

 

鍥犳锛屾€荤粨涓€涓嬩互涓婄殑鍋氭硶锛氬厛璁捐濂芥柊闂绘ā鏉匡紝鎶婇渶瑕佽鏇挎崲鐨勫唴瀹圭敤{ }鏀惧埌妯℃澘涓浉搴旂殑浣嶇疆锛岀劧鍚庤璁¤〃鍗曪紝鍐嶆槸鏈€鍚庣殑琛ㄥ崟澶勭悊绋嬪簭锛屾妸浠庤〃鍗曚腑鑾峰彇鐨勫彉閲忔浛鎹㈡ā鏉夸腑鐩稿簲鐨勫唴瀹瑰嵆鍙紝杩欐牱姣忔閮戒細鐢熸垚涓嶅悓鐨凥TML锛涘鏋滈渶瑕佷慨鏀笻TML鐨勫唴瀹逛篃鏄竴鏍风殑锛岃幏寰椾慨鏀瑰悗鐨勮〃鍗曞唴瀹瑰悗锛屽厛鐢?update 璇彞鏇存柊鏁版嵁搴擄紝鍐嶉噸鏂版浛鎹竴涓嬫ā鏉夸腑鐨勫唴瀹瑰嵆鍙紱鍒犻櫎鐨勮瘽锛屽厛delete琛ㄤ腑瑕佸垹闄ょ殑鍐呭锛屽啀鐢╱nlink($path) 鏉ュ垹闄TML鐨勭墿鐞嗘枃浠跺嵆鍙€?/p>

 

********************************************************

PHP鐢熸垚HTML妯℃澘瀹炰緥浠g爜

PHP鐢熸垚HTML鏂囦欢mb.php鍜孒TML妯℃澘鏂囦欢mb.htm锛屼竴鍏?涓枃浠躲€?/p>

-----------------

mb.php锛岃嫢鏃犳暟鎹紝鍒欑洿鎺cho杈撳嚭涔熷彲婕旂ず鎴愬姛

 

<?php

/**************************/

/* 鏂囦欢鍚?mb.php */

/*copyright www.nuskinbing.com */

/**************************/

ob_start();

$exec="select content from sql_content ";

$result = mysql_query($exec);

while($row= mysql_fetch_array($result))

{

$content=$row[鈥榗ontent鈥榏;

echo "$content ";

}

//鑻ユ棤鏁版嵁搴撳彲鐩存帴杈撳嚭 echo"www.nuskinbing.com";

$getcontent=ob_get_contents();//鍙栧緱寰幆杈撳嚭鐨?content鍐呭

ob_clean();//娓呴櫎缂撳啿杈撳嚭

/*********** 绗竴娆¤緭鍑哄唴瀹瑰彇寰楀畬姣?************/

 

ob_start();

$exec="select title from sql_title ";

$result = mysql_query($exec);

while($row= mysql_fetch_array($result))

{

$title=$row[鈥榯itle鈥榏;

echo "$title ";

}

//鑻ユ棤鏁版嵁搴撳彲鐩存帴杈撳嚭 echo"www.nuskinbing.com";

$gettitle=ob_get_contents();//鍙栧緱寰幆杈撳嚭鐨?title鍐呭

ob_clean();//娓呴櫎缂撳啿杈撳嚭

/******** 绗簩娆¤緭鍑哄唴瀹瑰彇寰楀畬姣?浠ユ绫绘帹 ********/

 

$fp=fopen("./mb.htm","r"); //鍙鎵撳紑妯℃澘

$str=fread($fp,filesize("./mb.htm"));//璇诲彇妯℃澘涓唴瀹?/p>

$str=str_replace("{content}",$content,$str);

//灏唟content}鏇挎崲涓?content

$str=str_replace("{title}",$title,$str);

//缁х画灏唟title}鏇挎崲涓?title

$handle=fopen("./index.htm","w+"); //鍐欏叆鏂瑰紡鎵撳紑鏂伴椈璺緞

fwrite($handle,$str); //鎶婂垰鎵嶆浛鎹㈢殑鍐呭鍐欒繘鐢熸垚鐨凥TML鏂囦欢

fclose($handle);//瀹屾垚鍏抽棴

?>

 

------------------------

 

mb.htm

 

<!---鏂囦欢鍚峬b.htm ----

copyright www.nuskinbing.com

----------------->

<html>

<head>

<title>{title}</title>

</head>

<body>

{content}

</body>

</html>

--鏉ヨ嚜浜掕仈缃?/p>

以上是关于鍑忓皯鏈嶅姟鍣ㄥ帇鍔沺hp鐢熸垚闈欐€亁ml鏂囦欢的主要内容,如果未能解决你的问题,请参考以下文章

java 鐢熸垚绛惧悕鏂囦欢

Error Code: 2006 - MySQL 鏈嶅姟鍣ㄥ凡绂荤嚎

涓€涓畝鍗曠殑web璇锋眰鏈嶅姟鍣ㄥ紑鍙慸emo

Linux涓璖shd鏈嶅姟閰嶇疆鏂囦欢浼樺寲鐗堟湰(/etc/ssh/sshd_config)

浜窐椤圭洰Day01馃毄鈽呪槄鈽咅煉?

linux浣跨敤Nginx鎼缓闈欐€佽祫婧愭湇鍔″櫒