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
920
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
94
DevOpsへの準備 便利なサービスで開発効率アップ -開発のためのSaaS利用の実際-
kashioka
0
250
PHP初心者セッション2017
kashioka
1
3.9k
どこからはじめるDevOps
kashioka
0
130
PHPカンファレンス2016 初心者セッション
kashioka
3
8.4k
Other Decks in Programming
See All in Programming
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
CSC509 Lecture 09
javiergs
PRO
0
140
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
4
640
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
ヤプリ新卒SREの オンボーディング
masaki12
0
130
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
330
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
120
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
250
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
330
みんなでプロポーザルを書いてみた
yuriko1211
0
260
Featured
See All Featured
Rails Girls Zürich Keynote
gr2m
94
13k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
It's Worth the Effort
3n
183
27k
Docker and Python
trallard
40
3.1k
Designing for Performance
lara
604
68k
Into the Great Unknown - MozCon
thekraken
32
1.5k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
A Philosophy of Restraint
colly
203
16k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
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