Rumah > pembangunan bahagian belakang > tutorial php > PHP中include跟require的区别

PHP中include跟require的区别

WBOY
Lepaskan: 2016-06-13 12:23:42
asal
853 orang telah melayarinya

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> }
Salin selepas log masuk

 



 

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan