首页 > 后端开发 > php教程 > PHP中include和require的区别,phpincluderequire_PHP教程

PHP中include和require的区别,phpincluderequire_PHP教程

WBOY
发布: 2016-07-13 09:44:30
原创
1036 人浏览过

PHP中include和require的区别,phpincluderequire

include和require的区别,其实两者没有太大的区别,如果要包含的文件不存在,include提示notice,然后继续执行下面的语句,require提示致命错误并且退出。

根据测试,win32平台下它们都是先包含后执行,所以被包含文件里最好不要再有include或require语句,这样会造成目录混乱。

或许*nux下情况不同,暂时还没测试。如果一个文件不想被包含多次可以使用include_once或require_once## 读取,写入文档数据:

<span> 1</span> <span>function</span> r(<span>$file_name</span><span>) {
</span><span> 2</span> <span>$filenum</span>=@<span>fopen</span>(<span>$file_name</span>,"r"<span>);
</span><span> 3</span> @<span>flock</span>(<span>$filenum</span>,<span>LOCK_SH);
</span><span> 4</span> <span>$file_data</span>=@<span>fread</span>(<span>$filenum</span>,<span>filesize</span>(<span>$file_name</span><span>));
</span><span> 5</span> @<span>fclose</span>(<span>$filenum</span><span>);
</span><span> 6</span> <span>return</span> <span>$file_data</span><span>;
</span><span> 7</span> <span>}
</span><span> 8</span> <span>function</span> w(<span>$file_name</span>,<span>$data</span>,<span>$method</span>="w"<span>){
</span><span> 9</span> <span>$filenum</span>=@<span>fopen</span>(<span>$file_name</span>,<span>$method</span><span>);
</span><span>10</span> <span>flock</span>(<span>$filenum</span>,<span>LOCK_EX);
</span><span>11</span> <span>$file_data</span>=<span>fwrite</span>(<span>$filenum</span>,<span>$data</span><span>);
</span><span>12</span> <span>fclose</span>(<span>$filenum</span><span>);
</span><span>13</span> <span>return</span> <span>$file_data</span><span>;
</span><span>14</span> }
登录后复制

 



 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1048763.htmlTechArticlePHP中include和require的区别,phpincluderequire include和require的区别,其实两者没有太大的区别,如果要包含的文件不存在,include提示notice,然后...
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板