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
930
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
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
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
複雑な仕様に立ち向かうアーキテクチャ
myohei
0
170
RWC 2024 DICOM & ISO/IEC 2022
m_seki
0
200
return文におけるstd::moveについて
onihusube
1
690
As an Engineers, let's build the CRM system via LINE Official Account 2.0
clonn
1
670
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
Full stack testing :: basic to basic
up1
1
930
急成長期の品質とスピードを両立するフロントエンド技術基盤
soarteclab
0
920
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.6k
第5回日本眼科AI学会総会_AIコンテスト_3位解法
neilsaw
0
170
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
180
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
Featured
See All Featured
Designing for Performance
lara
604
68k
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Designing Experiences People Love
moore
138
23k
Automating Front-end Workflow
addyosmani
1366
200k
We Have a Design System, Now What?
morganepeng
51
7.3k
How to Ace a Technical Interview
jacobian
276
23k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
0
94
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Embracing the Ebb and Flow
colly
84
4.5k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
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