일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- synchronized
- lombok
- 일급 컬렉션
- java
- Dependency Injection
- builder
- middleware
- factory
- spring security
- Volatile
- 일급 객체
- Spring
- nestjs
- Google OAuth
- OAuth 2.0
- Today
- Total
HJW's IT Blog
WEB: LECTURE 6 & 7 본문
#PHP 란?
> PHP Hypertext Preprocessor
> 서버쪽의 스크립트 언어
> 동적 페이지를 만드는데에 사용
> 브라우저가 .html 파일을 요청할 경우
> .html 은 정적 content이며, 서버는 해당 파일을 보낸다
> .php 는 동적 content 이여, 서버는 해당 파일을 읽고 결과를 보낸다
> PHP를 사용하는 이유
> Free and Open Source
> 호환성: 대부분의 웹 서버와 호환
> Simple: 내장된 기능이 많으며, 익숙한 syntax 사용
> Available: 대부분의 commercial web host에 내장되어 있다
> Well-Documented
<?php
print "Hello, world!";
?>
output: Hello, world!
> print 는 echo로 대체 가능하다
> php는 자동으로 여러 연산자를 변환한다
>> ex) 5+"7" = 12
> 변수 선언은 다음과 같
$user_name = "asdf";
print $user_name;
> Data Types
-> Int, Float, Boolean, String, Array, Object, NULL
$age = (int)"21";
#PHP Basic Syntax
> HTML 내에서 php를 실행할 수 있다
HTML Content
<?php
PHP CODE
?>
HTML Content...
> Math Operations
> 문자열 slicing 도 가능하다
$food="Ethiopian";
print $food[2];
output: h
$age=16;
print "$age"; #output: 16
print '$age'; #output: $age
print "{$age}" #output: 16
> String Operations
$name="Stefanie Hatcher";
$length=serlen($name); # 16
$cmp=strcmp($name, "Brian Le"); # > 0
$index=strpos($name, "e"); # 2
$first=substr($name,9,5); #Hatch
$surtoupper($name); #STEFANIE HATCHER
#Printing HTML tags in PHP
<h2> The answer is <?=6*7?> </h2>
#The answer is 42
#This is same as <?php print expr?>
<!DOCTYPE html>
<html>
<head><title>CSE 190 M: Embedded PHP</title></head>
<body>
<?php for ($i = 99; $i >= 1; $i--) { ?>
<p> <?= $i ?> bottles of beer on the wall, <br />
<?= $i ?> bottles of beer. <br />
Take one down, pass it around, <br />
<?= $i - 1 ?> bottles of beer on the wall. </p>
<?php } ?>
</body>
</html>
다음과 같은 형태로 응용할 수 있다
<body>
<?php for ($i = 1; $i <= 3; $i++) { ?>
<h<?= $i ?>>This is a level <?= $i ?> heading.</h<?= $i ?>>
<?php } ?>
</body>
'WEB' 카테고리의 다른 글
AWS VPC 구성 요소 총정리 (0) | 2025.04.04 |
---|---|
Web: Lecture 2 (0) | 2023.09.04 |