Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHPCON_TOKYO_2019_Bigginer.pdf

 PHPCON_TOKYO_2019_Bigginer.pdf

PHPカンファレンス 2019 初心者セッション
2019/12/1 @大田区産業プラザPiO
スライドの一部に古いデータが入っていました。すいません。

Hideo Kashioka

December 01, 2019
Tweet

More Decks by Hideo Kashioka

Other Decks in Programming

Transcript

  1. 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/ΑΓ
  2. LAMP LAPP LEMP Linux Apache MySQL PHP Linux Apache Postgre

    PHP Linux Nginx MySQL PHP ݺͼํ͸ OS+Web Server+Database+Script WAMPͱ͔LAMRɺMERNͱ͔΋ݕࡧͰ͸͋Γ·ͨ͠ɻ
  3. 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 Πϝʔδ໊ ެ։ϙʔτ ϗετଆͱίϯς φͷϙʔτ ϘϦϡʔϜͷϚ΢ϯτ ίϚϯυͷ࣮ߦ
 ϏϧτΠϯαʔό
  4. $a = “A” . “B”; $b = 1 + 2;

    μϒϧίʔςʔγϣϯ͸ด͡ͳͯ͘OK ଍ͨ͠Γ݁߹ͨ͠Γ
  5. $a = “A”; $b = “B”; $c = $a .

    $b; ม਺஋͕਺ࣈͳΒԋࢉ΋Մೳ ม਺Ͱ΋݁߹
  6. $a = "phpcon"; $b = 2017; echo $a . ($b

    + 2); http://localhost:8888/sample2.php
  7. <div> <?php if($a): ?> <div id='a'>ຬͨ͢</div> <?php else: ?> <div

    id=''>ຬͨ͞ͳ͍</div> <?php endif; ?> </div>
  8. 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͕ղऍ͞ΕΔ
  9. ྫΛಡΜͰΈΔ fopen — ϑΝΠϧ·ͨ͸ URL ΛΦʔϓϯ͢Δ whileϧʔϓ͸ɺPHPͰ࠷΋؆୯ͳλΠϓͷϧʔϓͰ͢ɻ count — ม਺ʹؚ·ΕΔ͢΂ͯͷཁૉɺ

    ͋Δ͍͸Φϒ δΣΫτʹؚ·ΕΔԿ͔ͷ਺Λ਺͑Δ fclose — Φʔϓϯ͞ΕͨϑΝΠϧϙΠϯλΛΫϩʔζ͢Δ ͜ΕΛ౿·͑ͯ
  10. αϯϓϧΛ࢖ͬͯΈΔ ಈ͔ͯ͠ΈΔ 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ϑΝΠϧΛஔ͍ͯΈ·͠ΐ͏ɻ
  11. <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); } ?>