include 파일 활용

홈페이지를 코딩하다보면 공동으로 반복적인 부분은 include 파일 이용해 처리하면 편리합니다. 이번에 zin.kr 사이트를 코딩하면서 공동 부분을 include로 처리해 봤습니다.

include 파일

include 파일 2가지 형태

include.php 파일


<?php
// 헤더 부분
function includeHeader() {
    include 'header.php';
}

// 바디 부분
function includeBody() {
    include 'body.php';
}

// 푸터 부분
function includeFooter() {
    include 'footer.php';
}
?>



* 아래와 같이 파일을 따로 만들지 않고 관리 할 수 있습니다.

<?php
// 헤더 부분
function includeHeader() {
    include 'header.php';
}

// 바디 부분
function includeBody() {
    include 'body.php';
}

// 푸터 부분
function includeFooter() {
?>
    <footer>
        <div class="container">
            <p>&copy; 2024 <a href="index.php" style="text-decoration: none; color: inherit;">URL Shortener</a>. All Rights Reserved.</p>
        </div>
    </footer>
<?php
}
?>

실제 추가 부분

원하는 페이지에 아래와 같이 입력하면 됩니다.

<?php
include 'include.php';

// 푸터 부분 삽입
includeFooter();
?>

코딩 및 웹관련 자료는 꾸준히 기록형으로 올릴 예정 입니다.

댓글 남기기

0%