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

PHP初心者セッション2017

 PHP初心者セッション2017

PHPを始めたばかりの人向けセッションです。今年は推奨環境をDockerにしています。

Hideo Kashioka

October 08, 2017
Tweet

More Decks by Hideo Kashioka

Other Decks in Technology

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 MariaDB PHP ݺͼํ͸ OS+Web Server+Database+Script WAMPͱ͔LAMRͱ͔΋ݕࡧͰ͸͋Γ·ͨ͠ɻ
  3. docker-compose.yml version: '3' services: php: image: php:7.1-alpine expose: - '8080'

    ports: - '8080:80' volumes: - ./apps:/home/www-data working_dir: /home/www-data command: php -S 0.0.0.0:80 docker Πϝʔδ໊ ެ։ϙʔτ ϗετଆͱίϯς φͷϙʔτ ϘϦϡʔϜͷϚ΢ϯτ ίϚϯυͷ࣮ߦ
 ϏϧτΠϯαʔό
  4. <?php $a = 1; $b = 2; echo $a +

    $b; echo '<br>'; echo $a . $b; http://localhost:8888/sample4.php
  5. <?php $a = "phpcon"; $b = 2016; echo $a .

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

    id=''>ຬͨ͞ͳ͍</div> <?php endif; ?> </div> http://localhost:8888/div.php
  7. 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
  8. αϯϓϧΛ࢖ͬͯΈΔ ಈ͔ͯ͠ΈΔ http://localhost:8888/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Λࠩ͠ସ͑ΔͱͲ͏ͳΔ͔
  9. ௐ΂ͯΈΔͱ fopen — ϑΝΠϧ·ͨ͸ URL ΛΦʔϓϯ͢Δ whileϧʔϓ͸ɺPHPͰ࠷΋؆୯ͳλΠϓͷϧʔϓͰ͢ɻ count — ม਺ʹؚ·ΕΔ͢΂ͯͷཁૉɺ

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