[PHP]Study_0328:include와 require

2022. 3. 28. 17:40PHP/Study

include함수를 통해 외부 php파일을 불러올 수 있다.

<!DOCTYPE html>
<html>
<body>

<h1>Welcome to my home page!</h1>
<p>Some text.</p>
<p>Some more text.</p>
<?php include 'footer.php';?>

</body>
</html>

include 할때의 주의할점은 파일 위치이다. 위의 코드에서는 실행하는 php와 include하는 php가 같은폴더안에 들어있어야 한다.

include_once하게되면, 한번만 실행한다는 것이다.

 

include와 유사하게, require함수를 사용할 수 있는데, require함수와 include함수의 차이점은,

에러가 일어났을때에 처리방법에 있다.

include는 warning을 일으키지만, require은 fatal error를 일으킨다. fatal은 치명적이란 뜻이여서, 더 강력한 경고를 할때에 사용된다.

require도 include와 같이 require_once를 사용할 수 있다.

'PHP > Study' 카테고리의 다른 글

[PHP]Study_0328:배열  (0) 2022.03.28
[PHP]Study_0328:함수  (0) 2022.03.28
[PHP]Study_0328:반복문  (0) 2022.03.28
[PHP]Study_0328:조건문  (0) 2022.03.28
[PHP]Study_0328:입력과 출력  (0) 2022.03.28