WEB/Server

PHP ๋‚ด์šฉ์ •๋ฆฌ - 1

kite707 2021. 1. 14. 15:27

https://opentutorials.org/course/3130

 

WEB2 - PHP - ์ƒํ™œ์ฝ”๋”ฉ

์ˆ˜์—…์†Œ๊ฐœ ์ด ์ˆ˜์—…์€ https://opentutorials.org ๋ฅผ ๋งŒ๋“ค์–ด๊ฐ€๋ฉด์„œ PHP์— ๋Œ€ํ•œ ์ง€์‹๊ณผ ๊ฒฝํ—˜์„ ๋™์‹œ์— ์ฑ„์›Œ๋“œ๋ฆฌ๊ธฐ ์œ„ํ•œ ๋ชฉ์ ์œผ๋กœ ๋งŒ๋“ค์–ด์ง„ ์ˆ˜์—…์ž…๋‹ˆ๋‹ค.  ์ˆ˜์—…๋Œ€์ƒ ์ด ์ˆ˜์—…์€ 1์–ต๊ฐœ์˜ ์›นํŽ˜์ด์ง€๋ฅผ ์ƒ์‚ฐํ•˜๋ฉด

opentutorials.org

bitnami๋ฅผ ๊น”๊ณ  ํ™˜๊ฒฝ์„ค์ •์„ ํ•˜๋Š”๊ฒƒ์€ ์•„๋ž˜ ๋งํฌ์— ์ž˜ ๋‚˜์™€์žˆ๋‹ค.

https://victorydntmd.tistory.com/192

 

[PHP ์„ค์น˜] Windows์—์„œ PHP ์„ค์น˜ - Bitnami

PHP๋Š” LAMP ์Šคํƒ์ด๋ผ๊ณ  ํ•ด์„œ, Linux , Apache , MySQL , PHP ์Šคํƒ์œผ๋กœ ๊ฐœ๋ฐœ์„ ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. LAMP ์Šคํƒ์˜ OS๋Š” Linux์ธ๋ฐ, ์ œ๋Œ€๋กœ PHP ๊ฐœ๋ฐœ์„ ํ•˜๋ ค๋ฉด Linux๋ฅผ ์‚ฌ์šฉํ•ด์„œ IDE ํˆด์— ๋งˆ์šดํŠธํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค...

victorydntmd.tistory.com

์„ค์ •์„ ์™„๋ฃŒํ•œ ๋’ค Bitnami\apache2\htdocs  ํด๋” ์•ˆ์— ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด ํŒŒ์ผ์„ ์—ด์–ด๋ณผ ์ˆ˜ ์žˆ๋‹ค. ๋งŒ์•ฝ ์„ค์น˜ ๊ฒฝ๋กœ๋ฅผ ๋‹ค๋ฅด๊ฒŒ ์ง€์ •ํ•˜์—ฌ ์‹ค์Šต์„ ์ง„ํ–‰ํ•  ๋•Œ ํŒŒ์ผ์„ ์—ฌ๋Š” ๋ฐฉ๋ฒ•์„ ๋ชจ๋ฅผ ๊ฒฝ์šฐ 

์ด๊ณณ์—์„œ Go to Application๋ฒ„ํŠผ์„ ๋ˆ„๋ฅธ ๋’ค ์—ด๊ณ ์‹ถ์€ ํŒŒ์ผ๋ช…์„ ์ž…๋ ฅํ•˜๋ฉด ๋œ๋‹ค.

๋‚˜์˜ ๊ฒฝ์šฐ ๋‘๊ฐ€์ง€ ํŒŒ์ผ์ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— Go to Application์„ ๋ˆ„๋ฅด๋ฉด ํ•˜๋‚˜์˜ ํŒŒ์ผ ์‹คํ–‰๊ฒฐ๊ณผ๋งŒ ์•Œ๋ ค์ค€๋‹ค.

index.htmlํŒŒ์ผ์˜ ์‹คํ–‰๊ฒฐ๊ณผ์ด๋‹ค.

์—ฌ๊ธฐ์„œ index.phpํŒŒ์ผ์„ ์—ด๊ณ ์‹ถ์„ ๊ฒฝ์šฐ /index.php ๋ฅผ ๋ถ™์—ฌ์ฃผ๋ฉด ๋œ๋‹ค.

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด index.phpํŒŒ์ผ์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.

PHP์—์„œ์˜ ์ถœ๋ ฅ

php์—์„œ ํŒŒ์ผ์„ ์ถœ๋ ฅํ•˜๋ ค๋ฉด echo ๋˜๋Š” print๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. 

<!doctype html>
<html>
    <body>
        <?php
        echo 1;
        echo"<br>"; //์ค„๋ฐ”๊ฟˆ
        print (1);
        ?>
    </body>
</html>

์œ„์™€ ์ฝ”๋“œ์˜ ์‹คํ–‰๊ฒฐ๊ณผ๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

PHP์—์„œ์˜ ์ˆซ์ž์™€ ๋ฌธ์ž์—ด

์ˆซ์ž์˜ ๊ฒฝ์šฐ ๊ทธ๋ƒฅ ์ž…๋ ฅํ•ด์ฃผ๋ฉด ๋œ๋‹ค. ์—ฐ์‚ฐ์ž์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ์—ฐ์‚ฐ ๊ฒฐ๊ณผ๋ฅผ ์•Œ๋ ค์ค€๋‹ค. 

<!doctype html>
<html>
    <body>
        <h2>1+1</h2>
        <?php
        echo 1+1;
        ?>
        <h2>2-1</h2>
        <?php
        echo 2-1;
        ?>
        <h2>3*2</h2>
        <?php
        echo 3*2;
        ?>
        <h2>4/2</h2>
        <?php
        echo 4/2;
        ?>
    </body>
</html>

๋ฌธ์ž์—ด์˜ ๊ฒฝ์šฐ "" ๋˜๋Š” ''๋กœ ๋ฌถ์–ด์ค€๋‹ค. 

<!doctype html>
<html>
    <body>
        <?php
            echo 'Hello World<br>';
            echo "Hello World<br>";
            print("Hello World<br>");
        ?>
    </body>
</html>

์–ด๋–ค๊ฒƒ์œผ๋กœ ์ถœ๋ ฅํ•ด๋„ ์ž˜ ์ถœ๋ ฅ์ด ๋œ๋‹ค.

๋ฌธ์ž์—ด ์•ˆ์— ""์ด๋‚˜ ''์„ ์ถœ๋ ฅํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ ์•„๋ž˜์™€ ๊ฐ™์ด ์ž…๋ ฅํ•˜๋ฉด ๋œ๋‹ค.

echo 'Hello "w"orld<br>';
echo "Hello \"w\"orld";

๋ฌธ์ž์—ด์„ ํ•ฉ์น˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ -> .์‚ฌ์šฉ

echo "๋ฌธ์ž์—ด1"."๋ฌธ์ž์—ด2"
//๋ฌธ์ž์—ด1๋ฌธ์ž์—ด2

strlenํ•จ์ˆ˜ : ๋ฌธ์ž์—ด์˜ ๊ธธ์ด ๋ฆฌํ„ด

echo strlen("Hello World");
//11

PHP์—์„œ์˜ ๋ณ€์ˆ˜

๋ณ€์ˆ˜ ์„ ์–ธ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

$๋ณ€์ˆ˜๋ช… = ๋‚ด์šฉ;
//ex
$a = 1;
$b = "Happy";

์œ„์—์„œ ๋ฐฐ์šด ๋ฌธ์ž์—ด ํ•ฉ์น˜๊ธฐ์™€ ๋ณ€์ˆ˜๋ฅผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•ด๋ณด์ž.

<!doctype html>
<html>
    <body>
        <?php
        $name = "kite";
            echo "Hailing from a long lost tribe of vastaya,
            Neeko can blend into any crowd by borrowing the appearances of others,
            even absorbing something of their emotional state to tell friend from 
            foe in an instant. No one is ever sure where—or who—Neeko might be, 
            but those who intend to do her harm will soon witness her true colors 
            revealed, and feel the full power of her primordial spirit magic unleashed 
            upon them. Neeko can look like an ally champion. Taking damage from enemy 
            Champions or casting damaging spells breaks the disguise.";
        ?>
    </body>
</html>

 

"Neeko"๋ผ๋Š” ๋ณ€์ˆ˜๋Š” ์œ„ ์ฝ”๋“œ์— 3๋ฒˆ ๋“ฑ์žฅํ•œ๋‹ค. ์ด๋•Œ ์ด๋ฆ„๋“ค์„ ๋ชจ๋‘ ๋ณ€์ˆ˜๋กœ ๋ฐ”๊ฟ” ์ง€์ •ํ•˜๋ฉด ๋‚˜์ค‘์— ์ด๋ฆ„์„ ๋ฐ”๊ฟ€ ๋•Œ ํ•œ๋ฒˆ์— ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ๋‹ค.

<!doctype html>
<html>
    <body>
        <?php
        $name = "kite";
            echo "Hailing from a long lost tribe of vastaya, ".$name." 
            can blend into any crowd by borrowing the appearances of others, 
            even absorbing something of their emotional state to tell friend 
            from foe in an instant. No one is ever sure where—or who—".$name." 
            might be, but those who intend to do her harm will soon witness her 
            true colors revealed, and feel the full power of her primordial spirit 
            magic unleashed upon them. ".$name." can look like an ally champion. 
            Taking damage from enemy Champions or casting damaging spells breaks 
            the disguise.";
        ?>
    </body>
</html>

์ด๋ฆ„์ด ์ž˜ ๋ฐ”๋€๊ฒƒ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ๋‹ค.