include와 require
Posted 2015. 4. 5. 19:52둘다 파일을 가져와서 적용 시킨다는 내용은 동일하지만
파일이 없을경우 include는 경고를 출력하고
require는 에러를 출력한다.
include 'test.php';
아래처럼 사용 해도 된다.
$file = 'test.php';
include $file;
딱 봐도 뭐같네. 걍 include ' 파일이름 ' 으로 사용 하자.
head.html 파일을 만든 후
head.html이당<BR>을 쓰고
나의 index.html 파일 내부에서
<?php
include 'head.html'; 하면 head.html 파일의 head.html이당이 출력 된다.
또는
head.html에서
<?php
$a = "12345";
?> 하고 난 뒤 다시 index 에서
include 'head.html'; 포함 후에
head.html의 변수를 콜 해도 출력이 된다.
<?php
include 'head.html';
echo $a; // 하면 12345가 출력 된다.
?>
반복문 내에서 사용 할 경우 계속 해서 불러 오겠지요.
한번만 불러오길 원하면 include_once, require_once 를 붙여주면 된다.
- Filed under : PHP/7. include와 require