PHP에서 여러 파일에 걸쳐 같은 내용이 반복될 경우

반복되는 내용을 하나의 파일로 만들어 포함시킬 수 있다.

반복의 예에는 함수, 헤더, 풋터 등이 있다.

파일을 포함시키기 위해 두 가지 키워드가 제공된다.

include()와 require() 함수가 제공되는데

에러처리를 제외한 모든 기능은 동일하다.

include()에서 에러가 발생하면 경고와 함께 실행을 계속하지만,

require()에서 에러가 발생하면 치명적 오류와 함께 실행을 중단하는 것이 다르다.

포함시키는 방식의 장점은

포함되는 파일을 수정해야되는 경우 포함되는 파일 하나만을 수정하면

포함하는 파일 모두에 반영됨으로써 작업 시간을 줄여줄 수 있다.

하지만 포함되는 파일의 내용을 각 포함하는 파일이 가지고 있었다고 한다면

그 파일들을 모두 찾아서 수정해야만 하는 번거로움이 있다.

다음을 참고하기 바란다.



You can insert the content of a file into a PHP file before the server executes it, with the include() or require() function. The two functions are identical in every way, except how they handle errors. The include() function generates a warning (but the script will continue execution) while the require() function generates a fatal error (and the script execution will stop after the error).

These two functions are used to create functions, headers, footers, or elements that can be reused on multiple pages.

This can save the developer a considerable amount of time. This means that you can create a standard header or menu file that you want all your web pages to include. When the header needs to be updated, you can only update this one include file, or when you add a new page to your site, you can simply change the menu file (instead of updating the links on all web pages).



일반적으로 include()보다는 require()를 사용할 것을 권장한다.

왜냐하면 파일이 없거나 파일 이름이 잘못된 상황에서

스크립트가 계속 실행되길 원하지 않을 것이기 때문이다.

다음을 참고하기 바란다.



It is recommended to use the require() function instead of include(), because scripts should not continue executing if files are missing or misnamed.



Reference:
http://www.w3schools.com/php/php_includes.asp

Posted by 알 수 없는 사용자
,