>  기사  >  백엔드 개발  >  PHP中include跟require的区别

PHP中include跟require的区别

WBOY
WBOY원래의
2016-06-13 12:23:42829검색

PHP中include和require的区别

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

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

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

<span style="color: #008080;"> 1</span> <span style="color: #0000ff;">function</span> r(<span style="color: #800080;">$file_name</span><span style="color: #000000;">) {</span><span style="color: #008080;"> 2</span> <span style="color: #800080;">$filenum</span>=@<span style="color: #008080;">fopen</span>(<span style="color: #800080;">$file_name</span>,"r"<span style="color: #000000;">);</span><span style="color: #008080;"> 3</span> @<span style="color: #008080;">flock</span>(<span style="color: #800080;">$filenum</span>,<span style="color: #000000;">LOCK_SH);</span><span style="color: #008080;"> 4</span> <span style="color: #800080;">$file_data</span>=@<span style="color: #008080;">fread</span>(<span style="color: #800080;">$filenum</span>,<span style="color: #008080;">filesize</span>(<span style="color: #800080;">$file_name</span><span style="color: #000000;">));</span><span style="color: #008080;"> 5</span> @<span style="color: #008080;">fclose</span>(<span style="color: #800080;">$filenum</span><span style="color: #000000;">);</span><span style="color: #008080;"> 6</span> <span style="color: #0000ff;">return</span> <span style="color: #800080;">$file_data</span><span style="color: #000000;">;</span><span style="color: #008080;"> 7</span> <span style="color: #000000;">}</span><span style="color: #008080;"> 8</span> <span style="color: #0000ff;">function</span> w(<span style="color: #800080;">$file_name</span>,<span style="color: #800080;">$data</span>,<span style="color: #800080;">$method</span>="w"<span style="color: #000000;">){</span><span style="color: #008080;"> 9</span> <span style="color: #800080;">$filenum</span>=@<span style="color: #008080;">fopen</span>(<span style="color: #800080;">$file_name</span>,<span style="color: #800080;">$method</span><span style="color: #000000;">);</span><span style="color: #008080;">10</span> <span style="color: #008080;">flock</span>(<span style="color: #800080;">$filenum</span>,<span style="color: #000000;">LOCK_EX);</span><span style="color: #008080;">11</span> <span style="color: #800080;">$file_data</span>=<span style="color: #008080;">fwrite</span>(<span style="color: #800080;">$filenum</span>,<span style="color: #800080;">$data</span><span style="color: #000000;">);</span><span style="color: #008080;">12</span> <span style="color: #008080;">fclose</span>(<span style="color: #800080;">$filenum</span><span style="color: #000000;">);</span><span style="color: #008080;">13</span> <span style="color: #0000ff;">return</span> <span style="color: #800080;">$file_data</span><span style="color: #000000;">;</span><span style="color: #008080;">14</span> }

 



 

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.