Slide 1

Slide 1 text

PHPΧϯϑΝϨϯε2017 PHPॳ৺ऀηογϣϯ ˌphpcon2017_4 ೔ຊPHPϢʔβձ ༗ݶձࣾΞϦ΢ʔϓ ദԬɹलஉ

Slide 2

Slide 2 text

ΞδΣϯμ ࣗݾ঺հ PHPͷจ๏ ࣮ફฤ ͓·͚

Slide 3

Slide 3 text

ࣗݾ঺հ ༗ݶձࣾΞϦ΢ʔϓ WEBγεςϜ։ൃɾDevOpsͷಋೖίϯαϧςΟϯά

Slide 4

Slide 4 text

PHPͱ͸

Slide 5

Slide 5 text

PHPͱ͸ PHP is a popular general-purpose scripting language that is especially suited to web development. Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world. http://php.net/ΑΓ

Slide 6

Slide 6 text

PHPͱ͸ WEB։ൃʹదͨ͠ݴޠ

Slide 7

Slide 7 text

PHPͷྺ࢙ 1994೥ʹRasmus͕ΦϯϥΠϯͰެ։͍ͯ͠Δܦྺॻ ͷΞΫηεཤྺΛௐ΂ΔͨΊʹ࢖ΘΕ͍ͯ·ͨ͠ ൴͸ͦͷεΫϦϓτ܈ΛʮPersonal Home Page Toolsʯͱ໊෇͚·ͨ͠ɻ http://php.net/manual/ja/history.php.php

Slide 8

Slide 8 text

PHPͷ؀ڥ

Slide 9

Slide 9 text

LAMP LAPP LEMP Linux Apache MySQL PHP Linux Apache Postgre PHP Linux Nginx MariaDB PHP ݺͼํ͸ OS+Web Server+Database+Script WAMPͱ͔LAMRͱ͔΋ݕࡧͰ͸͋Γ·ͨ͠ɻ

Slide 10

Slide 10 text

ͲΜͳ؀ڥͰ͸͡ΊΔ͔

Slide 11

Slide 11 text

ϗεςΟϯά Ϩϯλϧαʔό

Slide 12

Slide 12 text

AWS Microsoft Azure Google App Engine IBM Bluemix

Slide 13

Slide 13 text

Ծ૝؀ڥ Vmware VirtualBox Docker

Slide 14

Slide 14 text

खܰʹ͸͡ΊΔͳΒ XAMPP MAMP https://www.apachefriends.org/ https://www.mamp.info/

Slide 15

Slide 15 text

αʔόʔ͍Βͣ cloud9 http://c9.io https://ide.c9.io/kashioka/test

Slide 16

Slide 16 text

Docker https://www.docker.com/ Windows,MacରԠ

Slide 17

Slide 17 text

Docker https://hub.docker.com/_/php/

Slide 18

Slide 18 text

docker compose ෳ਺ͷίϯςφΛ؅ཧͰ͖Δɻ https://docs.docker.com/compose/gettingstarted/

Slide 19

Slide 19 text

ਪ঑։ൃ؀ڥ docker-composeΛ࢖༻͢Δ৔߹ dockerͷΠϯετʔϧ docker-compose.ymlͷ࡞੒ dockerͷىಈ

Slide 20

Slide 20 text

docker-compose.yml version: '3' services: php: image: php:7.1-alpine expose: - '8080' ports: - '8080:80' volumes: - ./apps:/home/www-data working_dir: /home/www-data command: php -S 0.0.0.0:80 docker Πϝʔδ໊ ެ։ϙʔτ ϗετଆͱίϯς φͷϙʔτ ϘϦϡʔϜͷϚ΢ϯτ ίϚϯυͷ࣮ߦ
 ϏϧτΠϯαʔό

Slide 21

Slide 21 text

σΟϨΫτϦ docker-compose.yml apps —>>͕͜͜dockerͱڞ༗͞Ε͍ͯΔʢϏϧτΠ ϯαʔόͷσΟϨΫτϦʣ ϩʔΧϧͷϑΝΠϧΛमਖ਼͢ΔͱdockerଆͰ࣮ߦՄ ೳ

Slide 22

Slide 22 text

ىಈํ๏ ର৅σΟϨΫτϦʹҠಈͯ͠ docker-compose up -d ։࢝ docker-compose stop ऴྃ

Slide 23

Slide 23 text

࣮ߦͯ͠ΈΔ

Slide 24

Slide 24 text

؀ڥ͸͙͢ʹͰ͖·͢ɻ ࢼͯ͠Έ·͠ΐ͏ɻ ※ձ৔಺Ͱͷμ΢ϯϩʔυ͸͝ԕྀ͍ͩ͘͞

Slide 25

Slide 25 text

PHPͷ֓ཁ

Slide 26

Slide 26 text

PHPͷجຊ PHPͷจ๏͸௚ײతͰ͢ɻ ଞͷݴޠΛ΍͍ͬͯͳ͍ํ͕ށ࿭͍·ͤΜɻ WEBߏஙʹ࠷దͳݴޠͰ͢ɻ ࣌ʹ࣮຿Ͱ࢖͏ʹ͸৭ʑग़͖ͯ·͢ ※ݸਓͷײ૝Ͱ͢

Slide 27

Slide 27 text

PHPλά ɹPHPϞʔυ; HTMLͷλάͷΑ͏ͳΠϝʔδ;

Slide 28

Slide 28 text

Ұ൪͔ΜͨΜͳαϯϓϧ http://localhost:8888/1st.php

Slide 29

Slide 29 text

֦ுࢠ ϑΝΠϧ໊.php

Slide 30

Slide 30 text

ߏจ ม਺͸$Ͱ࢝·Δ; จ຤͸;ͰऴΘΔ ܕએݴͳͲ͸ݫີʹߦΘͳͯ͘OK͕ͩޙʑ ໘౗…… ؆୯ͳαϯϓϧΛݟͯΈ·͠ΐ͏

Slide 31

Slide 31 text

Slide 32

Slide 32 text

PHP͔ΒHTML΋ग़ྗ

Slide 33

Slide 33 text

"; echo ""; echo "͜Ε͸PHPͰ͢"; echo ""; echo "

Slide 34

Slide 34 text

݁߹ͨ͠Γܭࢉͨ͠Γ .(υοτʣΛ࢖ͬͯจࣈྻͷ݁߹͕Ͱ͖ ·͢ɻ ਺஋ͷԋࢉ͸+-*/ php7·Ͱ͸จࣈྻͷ਺ࣈͰ΋଍͠ࢉͰ ͖͍ͯͨɻ

Slide 35

Slide 35 text

'; echo $a . $b; http://localhost:8888/sample4.php

Slide 36

Slide 36 text

Slide 37

Slide 37 text

PHPͷؔ਺ εΫϦϓτݴޠͷؔ਺͸਌͠Έ΍͍͢ ͳΜͱͳؔ͘਺Λ͍֮͑ͯΕ͹OK if foreach strlen htmlspecialchars nl2br mb_convert_encording

Slide 38

Slide 38 text

if ʙ else (endif) ৚݅൑ఆΛߦ͏ ৚݅Λຬͨ͢ຬͨ͞ͳ͍ͷ൑அΛߦ͏

Slide 39

Slide 39 text

Slide 40

Slide 40 text

ຬͨ͢
ຬͨ͞ͳ͍
http://localhost:8888/div.php

Slide 41

Slide 41 text

HTML૊ΈࠐΈܕͷαϯϓϧ Wordpressͷ৔߹ wp-content/themes/twentyseventeen/ header.php

Slide 42

Slide 42 text

foreach

Slide 43

Slide 43 text

htmlspecialchars ˍ"'<>ͱ͍ͬͨHTMLͰҙຯ͋ΔจࣈΛhtmlͷදࣔܗ ࣜʹม׵͢Δ = javascriptɺෆਖ਼ͳsql࣮ߦ౳ʹΑΔηΩϡϦςΟʔϦ εΫΛճආ͢Δɻ ೖྗ͞Εͨσʔλ͸ग़ྗ͢Δ௚લʹඞͣ htmlspecialcharsΛ௨͢

Slide 44

Slide 44 text

htmlspecialchars Test"; echo $new; Test"; echo htmlspecialchars($new,ENT_QUOTES); http://localhost:8888/sample3.php

Slide 45

Slide 45 text

ϑΝΠϧͷಡΈࠐΈ htmlͷྔ࢈ʹ΋ศར

Slide 46

Slide 46 text

require_once

Slide 47

Slide 47 text

஋Λऔಘ͢Δ ೖྗϑΥʔϜ͔Βೖྗ͞Εͨ஋ $_POST http://localhost:8888/get.php?id=123456 $_GET

Slide 48

Slide 48 text

஋ͷऔಘ

Slide 49

Slide 49 text

஋ͷ֬ೝ var_dump()

Slide 50

Slide 50 text

ؔ਺ ܁Γฦ͞ΕΔॲཧΛڞ௨Խ function ؔ਺໊([Ҿ਺,,,]) { } ͳΜͲ΋ग़ͯ͘ΔॲཧΛؔ਺Խ͓ͯ͘͠ɻ

Slide 51

Slide 51 text

ؔ਺αϯϓϧ function hsp($str) { return htmlspecialchars($str,ENT_QUOTES); } function add1($num = 0) { return $num + 1; }

Slide 52

Slide 52 text

͜Ε͘Β͍Θ͔Ε͹OK PHPͷΦϯϥΠϯϚχϡΞϧͷॆ࣮౓͕ੌ͍ PHPͷྺ࢙ ݴޠϦϑΝϨϯε

Slide 53

Slide 53 text

αϯϓϧΞϓϦέʔγϣϯ

Slide 54

Slide 54 text

࣮ફฤ λΠϜςʔϒϧΛͭ͘Δ

Slide 55

Slide 55 text

CSVσʔλΛ࡞Δ ϓϩάϥϜͰѻ͏ͨΊʹ͸CSV(ΧϯϚ۠੾Γ)΍TSV(λ ϒ۠੾Γ)ͱ͍ͬͨσʔλ͕खؒΛল͚Δ ExcelͰ࡞੒Մೳ

Slide 56

Slide 56 text

Tips MacͷExcelͷ৔߹վߦίʔυͷม׵͕ඞཁɻ Ұ୴file_get_contentsͳͲͰશ෦ಡΈࠐΜͰਖ਼نදݱͰ͔͑Δ ͳͲ Vi΍ίϚϯυϥΠϯͰม׵ͯ͠΋ྑ͍ :1,$ s/^M/¥r/g ͳͲ^M͸ctl+vͷޙʹctr+mͰೖྗ

Slide 57

Slide 57 text

CSVΛಡΈࠐΉ ؔ਺໊͕Θ͔Βͳ͚Ε͹ͱΓ͋͑ͣݕࡧ

Slide 58

Slide 58 text

fgetcsvͬͯͷ͕ݟ͔ͭͬͨ http://php.net/manual/ja/function.fgetcsv.php ͕Μ͹ͬͯಡΉͱΘ͔Δ Θ͔Βͳ͚Ε͹αϯϓϧΛ

Slide 59

Slide 59 text

αϯϓϧΛ࢖ͬͯΈΔ ಈ͔ͯ͠ΈΔ http://localhost:8888/sample1/list.php Warning: fopen(test.csv): failed to open stream: No such file or directory in /home/www-data/sample1/ list.php on line 3 Τϥʔ͕ͰΔͷͰcsvΛࠩ͠ସ͑ΔͱͲ͏ͳΔ͔

Slide 60

Slide 60 text

ϚχϡΞϧͰௐ΂ͯΈΑ͏ Θ͔Βͳ͍ؔ਺Λӈ্ʹೖΕͯΈΔɻ

Slide 61

Slide 61 text

ௐ΂ͯΈΔͱ fopen — ϑΝΠϧ·ͨ͸ URL ΛΦʔϓϯ͢Δ whileϧʔϓ͸ɺPHPͰ࠷΋؆୯ͳλΠϓͷϧʔϓͰ͢ɻ count — ม਺ʹؚ·ΕΔ͢΂ͯͷཁૉɺ ͋Δ͍͸Φϒ δΣΫτʹؚ·ΕΔԿ͔ͷ਺Λ਺͑Δ fclose — Φʔϓϯ͞ΕͨϑΝΠϧϙΠϯλΛΫϩʔζ͢Δ ͜ΕΛ౿·͑ͯ

Slide 62

Slide 62 text

ͳΜͱͳ͘Θ͔ͬͨ

Slide 63

Slide 63 text

ςʔϒϧͰදࣔͯ͠Έ·͠ΐ͏ɻ

Slide 64

Slide 64 text

ςʔϒϧͷߏ଄ ಉ͡Α͏ͳ෦෼ΛϧʔϓͰදࣔͤ͞Δ

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

৭ʑௐ੔ͯ͠ΈΑ͏ ߲໨Λ̐ͭදࣔ͢Δ ද߲ࣔ໨ʹ͸htmlspecialchars()Λ͔͚Δ http://localhost:8888/sample2/list.php

Slide 68

Slide 68 text

αϯϓϧιʔε

Slide 69

Slide 69 text

ίϯϕϯγϣϯϗʔϧηογϣϯ

ߜΓࠐΈɿ "; echo "". hsc($data[0])."\n"; echo "". hsc($data[1])."\n"; echo "". hsc($data[2])."\n"; echo "". hsc($data[3])."෼\n"; echo ""; } } fclose($handle); } ?>

Slide 70

Slide 70 text

ϚχϡΞϧͱ஥ྑ͘ͳΖ͏

Slide 71

Slide 71 text

֤஍Ͱ։࠵͞Ε͍ͯΔPHPΧ ϯϑΝϨϯε

Slide 72

Slide 72 text

࠙਌ձ ଞͷ։ൃऀ΍εϐʔΧʔͱ௚઀࿩͢νϟϯε!

Slide 73

Slide 73 text

͓קΊॻ੶ ʮ͍ͪ͹Μ΍͍͞͠PHPͷڭຊʯࢲ͕ॻ͍͍ͯ·͢ɻ ͍·ԿΛ࡞͍ͬͯΔͷ͔Λߟ͑Δ

Slide 74

Slide 74 text

·ͱΊ খ͍͞΋ͷͰ͍͍ͷͰॻ͍ͯݟ·͠ΐ͏ɻ ϚχϡΞϧ͕ศརͰ͢ɻ

Slide 75

Slide 75 text

ͱʹ͔͘ॻ͍ͯΈΔʂ Ҏ্

Slide 76

Slide 76 text

͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ ΧϯϑΝϨϯεΛָ͠ΜͰ͍ͩ͘͞ʂ ໌೔ͷ։ൃΧϯϑΝϨϯε
 ˌ͔͋͢Μɹ 2018೥4݄։࠵༧ఆʂ

Slide 77

Slide 77 text

PHPॳ৺ऀηογϣϯ ༗ݶձࣾΞϦ΢ʔϓ ദԬɹलஉ twitter,facebook @kashioka

Slide 78

Slide 78 text

No content