时间:2021-07-01 10:21:17 帮助过:28人阅读
- <br><?php <br>$file = fopen("test.txt","r"); <br>fread($file,"10"); <br>fclose($file); <br>?> <br><?php $file = fopen("test.txt","r"); fread($file,"10"); fclose($file); ?> <br> <br>例子 2 <br>读取整个文件: <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br><?php <br>$file = fopen("test.txt","r"); <br>fread($file,filesize("test.txt")); <br>fclose($file); <br>?> <br><?php $file = fopen("test.txt","r"); fread($file,filesize("test.txt")); fclose($file); ?> <br> <br><strong>3.开始替换模板变量.这里用到了PHP->str_replace();函数</strong> <br>定义和用法 <br>str_replace() 函数使用一个字符串替换字符串中的另一些字符。 <br>函数原型: <br>str_replace(find,replace,string,count) <br>//www.gxlcms.com/w3school/php/func_string_str_replace.asp.htm <br>提示和注释 <br>注释:该函数对大小写敏感。请使用 str_ireplace() 执行对大小写不敏感的搜索。 <br>注释:该函数是二进制安全的。 <br>3.替换模板变量后.使用PHP->echo();函数进行</li></ol></pre>输出 <br>编码部分: <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br>$title="测试标题"; <br>$file="测试内容"; <br>//打开这个模板 <br>$tempdata=fopen("test.html","r"); <br>//读取模板中的内容 <br>$str=fread($tempdata,filesize("test.html")); <br>//替换模板中的内容 <br>$str=str_replace('{$title}',$title,$str); <br>$str=str_replace('{$center}',$file,$str); <br>//</li></ol></pre>输出 <br>echo $str; <br>