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
940
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
PHP初心者セッション〜ChatGPTでゼロから動くプログラムを生み出そう!〜
kashioka
0
71
ここからはじめるDevOps
kashioka
0
95
DevOpsへの準備 便利なサービスで開発効率アップ -開発のためのSaaS利用の実際-
kashioka
0
260
PHP初心者セッション2017
kashioka
1
3.9k
どこからはじめるDevOps
kashioka
0
130
PHPカンファレンス2016 初心者セッション
kashioka
3
8.4k
Other Decks in Programming
See All in Programming
PHPカンファレンス 2024|共創を加速するための若手の技術挑戦
weddingpark
0
130
Simple組み合わせ村から大都会Railsにやってきた俺は / Coming to Rails from the Simple
moznion
3
2.1k
traP の部内 ISUCON とそれを支えるポータル / PISCON Portal
ikura_hamu
0
180
ドメインイベント増えすぎ問題
h0r15h0
2
560
VisionProで部屋の明るさを反映させるシェーダーを作った話
segur
0
100
functionalなアプローチで動的要素を排除する
ryopeko
1
190
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
9
2.3k
ChatGPT とつくる PHP で OS 実装
memory1994
PRO
3
190
歴史と現在から考えるスケーラブルなソフトウェア開発のプラクティス
i10416
0
300
AWS re:Invent 2024個人的まとめ
satoshi256kbyte
0
100
BEエンジニアがFEの業務をできるようになるまでにやったこと
yoshida_ryushin
0
190
サーバーゆる勉強会 DBMS の仕組み編
kj455
1
300
Featured
See All Featured
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
173
51k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.4k
Bash Introduction
62gerente
610
210k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
3
170
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
860
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Navigating Team Friction
lara
183
15k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
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