수업소개
함수를 직접 만들어서 애플리케이션의 복잡도를 높이고, 재활용성을 높이는 모습을 보여드리겠습니다.
index.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | <? php function print_title(){ if(isset($_GET['id'])){ echo $_GET['id']; } else { echo "Welcome"; } } function print_description(){ if(isset($_GET['id'])){ echo file_get_contents("data/".$_GET['id']); } else { echo "Hello, PHP"; } } function print_list(){ $ list = scandir ('./data'); $ i = 0 ; while($i < count($list)){ if($list[$i] != '.') { if($list[$i] != '..') { echo "<li>< a href=\"index.php?id=$list[$i]\">$list[$i]</ a ></ li >\n"; } } $i = $i + 1; } } ?> <!DOCTYPE html> < html > < head > < meta charset = "utf-8" > < title > <? php print_title(); ?> </ title > </ head > < body > < h1 >< a href = "index.php" >WEB</ a ></ h1 > < ol > <? php print_list(); ?> </ ol > < h2 > <? php print_title(); ?> </ h2 > <? php print_description(); ?> </ body > </ html > |