Heim > Backend-Entwicklung > PHP-Tutorial > PHP中include跟require的区别

PHP中include跟require的区别

WBOY
Freigeben: 2016-06-13 12:23:42
Original
848 Leute haben es durchsucht

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> }
Nach dem Login kopieren

 



 

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage