手记

php 读文件 替换 关键字

<?php

$name = '名称';

$age = '年龄';

$file_name = "aa.txt";

$strnum = strlen(file_get_contents($file_name));

$fp=fopen($file_name,'r');

while(!feof($fp))

{

 $buffer=fgets($fp,$strnum);

 $buffer = !empty($name) ? str_replace("{:name}","$name",$buffer) : $buffer; //替换内容

 $buffer = !empty($age) ? str_replace("{:age}","$age",$buffer) : $buffer;    //替换内容

 echo $buffer."<br />";

}

fclose($fp);

?>


0人推荐
随时随地看视频
慕课网APP