首頁 >後端開發 >php教程 >php鐢熸垚闈欐€侀〉闈唬鐮乢PHP鏁欑▼ | 甯涔嬪

php鐢熸垚闈欐€侀〉闈唬鐮乢PHP鏁欑▼ | 甯涔嬪

WBOY
WBOY原創
2016-07-20 11:08:261342瀏覽

php鐢熸垚闈欐€侀〉闈唬鐮佹湰娆剧敓鎴愰潤鎬侀〉闈㈢▼搴忓疄鐜板師鐞嗘槸鍋氬ソ鑷畾鐨勬ā鏉挎爣绛撅紝鐒跺悗鐢眘tr_replace鎶婃爣绛炬浛鎹㈡垚鎸囧畾鐨勫唴瀹癸紝鍐嶇敱fopen鐢熸垚鎸囧畾 鏂囦欢鍚嶇殑闈欐€侀〉闈紝杩欐牱灏監K浜嗐€?p>php鏁欑▼鐢熸垚闈欐€侀〉闈唬鐮?br />鏈鐢熸垚闈欐€侀〉闈㈢▼搴忓疄鐜板師鐞嗘槸鍋氬ソ鑷畾鐨勬ā鏉挎爣绛撅紝鐒跺悗鐢眘tr_replace鎶婃爣绛炬浛鎹㈡垚鎸囧畾鐨勫唴瀹癸紝鍐嶇敱fopen鐢熸垚鎸囧畾 鏂囦欢鍚嶇殑闈欐€侀〉闈紝杩欐牱灏眔k浜嗐€?/p>

header('content-type:text/html;charset=utf-8');
if(!function_exists('file_get_contents')){ //濡傛灉绯荤粺娌℃湁file_get_contents()鍑芥暟
 function file_get_contents($file){ //鑷繁鍐檉ile_get_contents()鍑芥暟
  $fp = fopen($file,'r');
  $content = fread($fp,filesize($file));
  fclose($fp);
  return $content;
 }
}
$tmp_file = 'template.html'; //妯℃澘鏂囦欢
$content = file_get_contents($tmp_file); //鑾峰緱妯℃澘鏂囦欢鍐呭
$title = "title"; //妯℃澘鍙橀噺title瑕佹浛鎹㈢殑鍊?br />$text = 'text'; //妯℃澘鍙橀噺text瑕佹浛鎹㈢殑鍊?br />$content = str_replace('',$title,$content); //鏇挎崲妯℃澘鍙橀噺title
$content = str_replace('',$text,$content); //鏇挎崲妯℃澘鍙橀噺text
//echo $content; //鏄剧ず鏇挎崲鍚庣殑妯℃澘鏂囦欢鍐呭
makehtml('news.html',$content);//鍐欏叆鐢熸垚鍚庣殑闈欐€佹枃浠跺唴瀹瑰埌news.html鏂囦欢
echo '鏌ョ湅鏂囦欢';
function makehtml($file,$content){
 $fp = fopen($file,'w');
 fwrite($fp,$content);
 fclose($fp);
}
?>

//template.html





makehtml


杩欐槸妯℃澘鍙橀噺title------


杩欐槸妯℃澘鍙橀噺text------


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/444874.htmlTechArticlephp鐢熸垚闈欐€侀〉闈唬鐮佹湰娆剧敓鎴愰潤鎬侀〉闈㈢▼搴忓疄鐜板師鐞嗘槸鍋氬ソ鑷畾鐨勬ā鏉挎爣绛撅紝鐒跺悗鐢眘tr_replace鎶婃爣绛炬浛鎹㈡垚鎸囧畾鐨勫唴瀹癸紝鍐嶇敱fopen鐢熸垚鎸囧畾...
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn