Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
PHPCON_TOKYO_2019_Bigginer.pdf
Search
Hideo Kashioka
December 01, 2019
Programming
0
900
PHPCON_TOKYO_2019_Bigginer.pdf
PHPカンファレンス 2019 初心者セッション
2019/12/1 @大田区産業プラザPiO
スライドの一部に古いデータが入っていました。すいません。
Hideo Kashioka
December 01, 2019
Tweet
Share
More Decks by Hideo Kashioka
See All by Hideo Kashioka
ここからはじめるDevOps
kashioka
0
93
DevOpsへの準備 便利なサービスで開発効率アップ -開発のためのSaaS利用の実際-
kashioka
0
240
PHP初心者セッション2017
kashioka
1
3.9k
どこからはじめるDevOps
kashioka
0
130
PHPカンファレンス2016 初心者セッション
kashioka
3
8.4k
Other Decks in Programming
See All in Programming
Jakarta EE meets AI
ivargrimstad
0
390
ドメイン駆動設計を実践するために必要なもの
bikisuke
4
330
[DroidKaigi 2024] Android ViewからJetpack Composeへ 〜Jetpack Compose移行のすゝめ〜 / From Android View to Jetpack Compose: A Guide to Migration
syarihu
1
660
GenU導入でCDKに初挑戦し、悪戦苦闘した話
hideg
0
170
Composing an API the *right* way (Droidcon New York 2024)
zsmb
2
140
Rubyとクリエイティブコーディングの輪の広がり / The Growing Circle of Ruby and Creative Coding
chobishiba
1
270
今インフラ技術をイチから学び直すなら
yuhta28
1
140
GoのIteratorに詳しくなってしまう
inatonix
1
210
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
0
120
The Shape of a Service Object
inem
0
520
オートマトン学習しろ / Do automata learning
makenowjust
3
130
いまから追い上げる、Jetpack Compose トレーニング
nyafunta9858
0
610
Featured
See All Featured
Fontdeck: Realign not Redesign
paulrobertlloyd
80
5.1k
From Idea to $5000 a Month in 5 Months
shpigford
379
46k
Embracing the Ebb and Flow
colly
83
4.4k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
45
4.8k
Side Projects
sachag
451
42k
Design by the Numbers
sachag
277
19k
4 Signs Your Business is Dying
shpigford
179
21k
What the flash - Photography Introduction
edds
67
11k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
158
15k
WebSockets: Embracing the real-time Web
robhawkes
59
7.3k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Docker and Python
trallard
39
3k
Transcript
PHPΧϯϑΝϨϯε2019 PHPॳ৺ऀηογϣϯ #phpcon #Track5 ຊPHPϢʔβձ ༗ݶձࣾΞϦʔϓ ദԬɹलஉ
ΞδΣϯμ ࣗݾհ PHPͷจ๏ ࣮ફฤ ͓·͚
ࣗݾհ ༗ݶձࣾΞϦʔϓɹऔకࣾ WEBγεςϜ։ൃɺνʔϜϏϧσΟϯά DevOps,CIͷಋೖίϯαϧςΟϯά εΫϥϜϚελʔ
ରͱͳΔօ༷ PHPॻ͍ͨ͜ͱແ͍ ೖॻಡΜ͚ͩͲɺ్தͰ࠳ં ଞͷݴޠͰೖఔ
ҠಈλΠϜ
PHPͱ
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/ΑΓ
PHPͱ WEB։ൃʹదͨ͠ݴޠ
PHPͷྺ࢙ 1994ʹRasmus͕ΦϯϥΠϯͰެ։͍ͯ͠Δܦྺॻ ͷΞΫηεཤྺΛௐΔͨΊʹΘΕ͍ͯ·ͨ͠ ൴ͦͷεΫϦϓτ܈ΛʮPersonal Home Page Toolsʯͱ໊͚·ͨ͠ɻ http://php.net/manual/ja/history.php.php
PHPͷsoftware
EC-CUBEגࣜձࣾΠʔγʔΩϡʔϒͷඪͰ͢
PHPͷڥ
LAMP LAPP LEMP Linux Apache MySQL PHP Linux Apache Postgre
PHP Linux Nginx MySQL PHP ݺͼํ OS+Web Server+Database+Script WAMPͱ͔LAMRɺMERNͱ͔ݕࡧͰ͋Γ·ͨ͠ɻ
ͲΜͳڥͰ͡ΊΔ͔
ϗεςΟϯά Ϩϯλϧαʔό
AWS Azure GCP ͦͷଞ
ϩʔΧϧ XAMPP MAMP
aws cloud9 ͔ͭͯಠཱͨ͠αʔϏεɻ ݱࡏAWSʹ౷߹͞Εͨɻ ౦ژϦʔδϣϯαϙʔτ͞Ε͍ͯͳ͍ AWSͷ͕ࣝඞཁ ϦϞʔταʔόଓͰ͖Δ http://c9.io
Docker https://www.docker.com/ Windows,MacରԠ
Docker https://hub.docker.com/_/php/
docker compose ෳͷίϯςφΛཧͰ͖Δɻ https://docs.docker.com/compose/gettingstarted/
DockerʹΑΔ։ൃڥ docker-composeΛ༻͢Δ߹ dockerͷΠϯετʔϧ docker-compose.ymlͷ࡞ dockerͷىಈ
docker-compose.yml version: '3' services: php: image: php:7.4.0-fpm-alpine3.10 expose: - '8080'
ports: - '8080:80' volumes: - ./phpapps:/home/www-data working_dir: /home/www-data command: php -S 0.0.0.0:80 docker Πϝʔδ໊ ެ։ϙʔτ ϗετଆͱίϯς φͷϙʔτ ϘϦϡʔϜͷϚϯτ ίϚϯυͷ࣮ߦ ϏϧτΠϯαʔό
σΟϨΫτϦߏ docker-compose.yml apps —>>͕͜͜dockerͱڞ༗͞Ε͍ͯΔʢϏϧτΠ ϯαʔόͷσΟϨΫτϦʣ ϩʔΧϧͷϑΝΠϧΛमਖ਼͢ΔͱdockerଆͰ࣮ߦՄ ೳ
ىಈํ๏ ରσΟϨΫτϦʹҠಈͯ͠ docker-compose up -d ։࢝ docker-compose stopऴྃ
࣮ߦͯ͠Έ·͠ΐ͏ɻ index.phpΛ࡞ͯ֬͠ೝͯ͠Έ·͠ΐ͏ http://localhost:8888
None
ڥ͙͢ʹͰ͖·͢ɻ ࢼͯ͠Έ·͠ΐ͏ɻ ※ձͰͷμϯϩʔυ͝ԕྀ͍ͩ͘͞
PHPͷ֓ཁ
PHPͷجຊ PHPͷจ๏ײతͰ͢ɻ ଞͷݴޠΛ͍ͬͯͳ͍ํ͕ށ͍·ͤΜɻ WEBߏஙʹ࠷దͳݴޠͰ͢ɻ ࣌ʹ࣮Ͱ͏ʹ৭ʑग़͖ͯ·͢ ※ݸਓͷײͰ͢
PHPλά <?php ?>ɹPHPϞʔυ; HTMLͷλάͷΑ͏ͳΠϝʔδ;
<html> <body> <?php echo "͜Μʹͪ"; ?> </body> </html> Ұ൪͔ΜͨΜͳαϯϓϧ http://localhost:8888/1st.php
<html> <body> <?php echo "͜Μʹͪ"; ?> </body> </html> Ұ൪͔ΜͨΜͳαϯϓϧ http://localhost:8888/1st.php
֦ுࢠ ϑΝΠϧ໊.php
ߏจ ม$Ͱ࢝·Δ; จ;ͰऴΘΔ ܕએݴͳͲݫີʹߦΘͳͯ͘OK͕ͩޙʑ ໘…… ؆୯ͳαϯϓϧΛݟͯΈ·͠ΐ͏
<?php $a = '͜Μʹͪ'; echo $a;
PHP͔ΒHTMLग़ྗ
<?php echo "<html>"; echo "<body>"; echo "͜ΕPHPͰ͢"; echo "</body>"; echo
"</html>"; http://localhost:8888/sample0.php
$a = “A” . “B”; $b = 1 + 2;
μϒϧίʔςʔγϣϯด͡ͳͯ͘OK ͨ͠Γ݁߹ͨ͠Γ
$a = “A”; $b = “B”; $c = $a .
$b; ม͕ࣈͳΒԋࢉՄೳ มͰ݁߹
$a = "phpcon"; $b = 2017; echo $a . ($b
+ 2); http://localhost:8888/sample2.php
PHPͷؔ if foreach strlen htmlspecialchars nl2br mb_convert_encording
if ʙ else (endif) ݅ఆΛߦ͏ ݅Λຬͨ͢ຬͨ͞ͳ͍ͷஅΛߦ͏
<?php if($a) { echo '݅Λຬͨ͢'; } else { echo '݅Λຬͨ͞ͳ͍';
}
<div> <?php if($a): ?> <div id='a'>ຬͨ͢</div> <?php else: ?> <div
id=''>ຬͨ͞ͳ͍</div> <?php endif; ?> </div>
ͲΜͳ࣌ʹ͏͔ ೖྗ͕༧ͱҧ͏ औಘͨ͠ʹΑͬͯॲཧΛΓ͚Δ
HTMLΈࠐΈܕͷαϯϓϧ WordPressͷ߹ wp-content/themes/twentynineteen/ header.php
܁Γฦ͠ॲཧ
foreach <?php $numbers = array('2','3','4','5','6'); foreach($numbers as $val) { echo
$val; } http://localhost:8080/sample5.php
htmlspecialchars ˍ"'<>ͱ͍ͬͨHTMLͰҙຯ͋ΔจࣈΛhtmlͷදࣔܗࣜʹม ͢Δ = javascriptɺෆਖ਼ͳsql࣮ߦʹΑΔηΩϡϦςΟʔϦεΫΛ ճආ͢Δɻ ೖྗ͞Εͨσʔλग़ྗ͢Δલʹඞͣhtmlspecialchars Λ௨͢ ϑϨʔϜϫʔΫΛ͍ͬͯͯ֬ೝ͠·͠ΐ͏ɻ
htmlspecialchars <?php $new ="<a href='test'>Test</a>"; echo $new; <?php $new ="<a
href='test'>Test</a>"; echo htmlspecialchars($new,ENT_QUOTES); http://localhost:8888/sample3.php HTML͕ղऍ͞ΕΔ
ϑΝΠϧͷಡΈࠐΈ htmlͷྔ࢈ʹศར
require_once <?php require_once('header.html'); require_once('body.php'); require_once('footer.html'); http://localhost:8888/require.php
Λऔಘ͢Δ ೖྗϑΥʔϜ͔Βೖྗ͞Εͨ $_POST http://localhost:8888/get.php?id=123456 $_GET Կ͕ೖͬͯ͘Δ͔Θ͔Βͳ͍ͷͰར༻·Ͱʹҙ͢Δʂ όϦσʔγϣϯDBઐ༻ͷΤεέʔϓॲཧɺϓϦϖΞʔυε ςʔτϝϯτͳͲ
ͷऔಘ <?php echo $_GET['id']; echo $_POST['id']; ࣮ࡍhtmlspecialchars()ͨ͠Γ
ͷ֬ೝ var_dump() http://localhost:8888/get.php?id=1
ؔ ܁Γฦ͞ΕΔॲཧΛڞ௨Խ function ໊ؔ([Ҿ,,,]) { } ͳΜͲग़ͯ͘ΔॲཧΛؔԽ͓ͯ͘͠ɻ
ؔαϯϓϧ function hsp($str) { return htmlspecialchars($str,ENT_QUOTES); } function add1($num =
0) { return $num + 1; }
͜Ε͘Β͍Θ͔ΕOK ࣍Ϋϥεͷѻ͍ͳͲΛษڧ͠·͠ΐ͏ PHPͷΦϯϥΠϯϚχϡΞϧͷॆ࣮͕ੌ͍ PHPͷྺ࢙ ݴޠϦϑΝϨϯε
࣍ͷҰา
PHPΞϓϦέʔγϣϯΛ Πϯετʔϧͯ͠ΈΔ WordPress Drupal EC-Cube Xoops
ϑϨʔϜϫʔΫΛ ͬͯΈΑ͏ Laraval CakePHP Symphony
࣮ફฤ CSVϑΝΠϧΛಡΈࠐΜͰදࣔ͢ΔϓϩάϥϜΛ࡞Δ
ࡐྉ ։ൃڥ ͓͖ͳΤσΟλ php.net ϚχϡΞϧ CSVϑΝΠϧ
CSVΛಡΈࠐΉ ໊͕ؔΘ͔Βͳ͚ΕͱΓ͋͑ͣݕࡧ
fgetcsvͬͯͷ͕ݟ͔ͭͬͨ http://php.net/manual/ja/function.fgetcsv.php ͕ΜͬͯಡΉͱΘ͔Δ Θ͔Βͳ͚ΕαϯϓϧΛ
php.net ΑΓ
php.net ΑΓ
ϚχϡΞϧͰௐͯΈΑ͏ Θ͔Βͳ͍ؔΛӈ্ʹೖΕͯΈΔɻ
ྫΛಡΜͰΈΔ fopen — ϑΝΠϧ·ͨ URL ΛΦʔϓϯ͢Δ whileϧʔϓɺPHPͰ࠷؆୯ͳλΠϓͷϧʔϓͰ͢ɻ count — มʹؚ·ΕΔͯ͢ͷཁૉɺ
͋Δ͍Φϒ δΣΫτʹؚ·ΕΔԿ͔ͷΛ͑Δ fclose — Φʔϓϯ͞ΕͨϑΝΠϧϙΠϯλΛΫϩʔζ͢Δ ͜ΕΛ౿·͑ͯ
ͳΜͱͳ͘Θ͔ͬͨ
αϯϓϧΛͬͯΈΔ ಈ͔ͯ͠ΈΔ http://localhost:8080/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ϑΝΠϧΛஔ͍ͯΈ·͠ΐ͏ɻ
CSVσʔλΛ࡞Δ "෦","λΠτϧ","։࢝࣌ࠁ","࣌ؒ" "ക","LaravelͰTDDΛମݧ͠Α͏","11:00","60" "ക","PHP,Go,ElasticsearchʹΑΔɺ@cosmeΛ5ഒ͘͢ΔऔΓΈ","13:00","25" "ക","ΞʔΩςΫνϟઃܭͱUXઃܭಉ͡ͳͷ͔!!??","13:35","25" "ക","Laravel × ϨΠϠʔυΞʔΩςΫνϟΛ࣮ફͯ͠ಘΒΕͨݟͱল","14:00","25" "","ಠཱͨ͠ίΞϨΠϠύλʔϯʹΑΔ PHP
ΞϓϦέʔγϣϯͷ࣮","11:00","60" "","VOYAGEͷΤϯδχΞධՁ੍ͬͯͲΜͳײ͡ͳͷ͔25Ͱϛχ࠶ԋ","13:00","25" "","PHPΛબͿཧ༝","13:35","25" test.csv
ϑΝΠϧΛஔ͍࣮ͯߦͯ͠Έ·͠ΐ͏
None
ςʔϒϧͰදࣔͯ͠Έ·͠ΐ ͏ɻ
ςʔϒϧͷߏ ಉ͡Α͏ͳ෦ΛϧʔϓͰදࣔͤ͞Δ
None
৭ʑௐͯ͠ΈΑ͏ දࣔ͢Δ߲Λબ͢Δ ද߲ࣔʹhtmlspecialchars()Λ͔͚Δ ߜΓࠐΈΛೖΕΔ http://localhost:8080/sample2/list.php
αϯϓϧιʔε
<h1>ίϯϕϯγϣϯϗʔϧηογϣϯ</h1> ߜΓࠐΈɿ<a href="list2.php?room="></a> <a href="list2.php?room=ക">ക</a> <table border=1> <?php if (($handle
= fopen("timetable2.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { if ($_GET['room'] === $data[0] ) { echo "<tr>"; echo "<td>". hsc($data[0])."</td>\n"; echo "<td>". hsc($data[1])."</td>\n"; echo "<td>". hsc($data[2])."</td>\n"; echo "<td>". hsc($data[3])."</td>\n"; echo "</tr>"; } } fclose($handle); } ?> </table> <?php function hsc($str) { return htmlspecialchars($str,ENT_QUOTES); } ?>
None
ϚχϡΞϧͱྑ͘ͳΖ͏
࠙ձ ଞͷ։ൃऀεϐʔΧʔͱ͢νϟϯε!
͓קΊॻ੶ ʮ͍ͪΜ͍͞͠PHPͷڭຊʯࢲ͕ॻ͍͍ͯ·͢ɻ ͍·ԿΛ࡞͍ͬͯΔͷ͔Λߟ͑Δ
·ͱΊ PHPͷڥΛ࡞ͬͯΈ·͠ΐ͏ɻ PHPΞϓϦέʔγϣϯΛΠϯετʔϧͯ͠Έ·͠ΐ͏ ؆୯ͳϓϩάϥϜΛॻ͍ͯΈ·͠ΐ͏ɻ ϑϨʔϜϫʔΫͷνϡʔτϦΞϧΛͯ͠Έ·͠ΐ͏ɻ ΞϓϦͷΧελϚΠζΛͯ͠Έ·͠ΐ͏ɻ
ͥͻ͓ࢼ͍ͩ͘͠͞ʂ
͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ ΧϯϑΝϨϯεΛָ͠ΜͰ͍ͩ͘͞ʂ ໌ͷ։ൃΧϯϑΝϨϯε ΞεΧϯτʔΫφΠτɹ ΞεΧϯτʔΫφΠτͰݕࡧʂ 12/6։࠵༧ఆʂ
PHPॳ৺ऀηογϣϯ ༗ݶձࣾΞϦʔϓ ദԬɹलஉ twitter,facebook @kashioka
None