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> }
以上就介紹了PHP中include和require的區別,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。