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

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

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}>',$title,$content); //鏇挎崲妯℃澘鍙橀噺title
$content = str_replace('<{text}>',$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------<{title}>


杩欐槸妯℃澘鍙橀噺text------<{text}>


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/444874.htmlTechArticlephp鐢熸垚闈欐€侀〉闈唬鐮佹湰娆剧敓鎴愰潤鎬侀〉闈㈢▼搴忓疄鐜板師鐞嗘槸鍋氬ソ鑷畾鐨勬ā鏉挎爣绛撅紝鐒跺悗鐢眘tr_replace鎶婃爣绛炬浛鎹㈡垚鎸囧畾鐨勫唴瀹癸紝鍐嶇敱fopen鐢熸垚鎸囧畾...

文章来源:https://www.php.cn/faq/305661.html

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复

    作者信息

    相关文章