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

PHPカンファレンス2016 初心者セッション

267cdf0d184f715349459a0af9e6b0ff?s=47 Hideo Kashioka
November 03, 2016

PHPカンファレンス2016 初心者セッション

267cdf0d184f715349459a0af9e6b0ff?s=128

Hideo Kashioka

November 03, 2016
Tweet

Transcript

  1. PHPΧϯϑΝϨϯε2016 PHPॳ৺ऀηογϣϯ ೔ຊPHPϢʔβձ ༗ݶձࣾΞϦ΢ʔϓ ദԬɹलஉ

  2. ΞδΣϯμ ࣗݾ঺հ PHPͷจ๏ ࣮ફฤ ͓·͚

  3. ࣗݾ঺հ ༗ݶձࣾΞϦ΢ʔϓ WEBγεςϜ։ൃ ͦΕʹ·ͭΘΔ͢΂ͯ ಛʹՐফ͠Λߦ͏͜ͱ͕ଟ͍Ͱ͢

  4. PHPͱ͸

  5. 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/ΑΓ
  6. PHPͱ͸ WEB։ൃʹదͨ͠ݴޠ

  7. PHPͷྺ࢙ 1994೥ʹRasmus͕ΦϯϥΠϯͰެ։͍ͯ͠Δܦྺॻ ͷΞΫηεཤྺΛௐ΂ΔͨΊʹ࢖ΘΕ͍ͯ·ͨ͠ ൴͸ͦͷεΫϦϓτ܈ΛʮPersonal Home Page Toolsʯͱ໊෇͚·ͨ͠ɻ http://php.net/manual/ja/history.php.php

  8. PHPͷ؀ڥ

  9. LAMP LAPP LEMP Linux Apache MySQL PHP Linux Apache Postgre

    PHP Linux Nginx MariaDB PHP ݺͼํ͸ OS+Web Server+Database+Script
  10. ͲΜͳ؀ڥͰ͸͡ΊΔ͔

  11. AWS Microsoft Azure Google App Engine IBM Softlayear

  12. ϗεςΟϯά Ϩϯλϧαʔό

  13. Ծ૝؀ڥ Vmware VirtualBox

  14. खܰʹ͸͡ΊΔͳΒ XAMPP MAMP

  15. αʔόʔ͍Βͣ cloud9 http://c9.io https://ide.c9.io/kashioka/test

  16. ؀ڥ͸ࢥ͍ͷ֎͙͢ʹͰ͖·͢ɻ ͥͻɺࢼͯ͠Έ·͠ΐ͏ɻ

  17. PHPͷ֓ཁ

  18. PHPͷجຊ PHPͷจ๏͸௚ײతͰ͢ɻ ଞͷݴޠΛ΍͍ͬͯͳ͍ํ͕ށ࿭͍·ͤΜɻ WEBߏஙʹ࠷దͳݴޠͰ͢ɻ ࣌ʹ࣮຿Ͱ࢖͏ʹ͸৭ʑग़͖ͯ·͢ ※ݸਓͷײ૝Ͱ͢

  19. PHPλά <?php ?>ɹPHPϞʔυ; HTMLͷλάͷΑ͏ͳΠϝʔδ;

  20. <html> <body> <?php echo "͜Μʹͪ͸"; ?> </body> </html> Ұ൪͔ΜͨΜͳαϯϓϧ http://localhost:8888/1st.php

  21. ֦ுࢠ ϑΝΠϧ໊.php

  22. ߏจ ม਺͸$Ͱ࢝·Δ; จ຤͸;ͰऴΘΔ ܕએݴͳͲ͸ݫີʹߦΘͳͯ͘OK͕ͩޙʑ ໘౗…… ؆୯ͳαϯϓϧΛݟͯΈ·͠ΐ͏

  23. <?php $a = '͜Μʹͪ͸'; echo $a;

  24. PHP͔ΒHTML΋ग़ྗ

  25. <?php echo "<html>"; echo "<body>"; echo "͜Ε͸PHPͰ͢"; echo "</body>"; echo

    "</html>"; http://localhost:8888/sample0.php
  26. ݁߹ͨ͠Γܭࢉͨ͠Γ .(υοτʣΛ࢖ͬͯจࣈྻͷ݁߹ ͕Ͱ͖·͢ɻ ਺஋ͷԋࢉ͸+-*/

  27. <?php $a = 1; $b = 2; echo $a +

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

    "/" . $b + 1; http://localhost:8888/sample2.php
  29. PHPͷؔ਺ εΫϦϓτݴޠͷؔ਺͸਌͠Έ΍͍͢ ͳΜͱͳؔ͘਺Λ͍֮͑ͯΕ͹OK if foreach strlen htmlspecialchars nl2br mb_convert_encording

  30. if ʙ else (endif) ৚݅൑ఆΛߦ͏ ৚݅Λຬͨ͢ຬͨ͞ͳ͍ͷ൑அΛߦ͏

  31. <?php if($a) { echo '৚݅Λຬͨ͢'; } else { echo '৚݅Λຬͨ͞ͳ͍';

    } http://localhost:8888/if.php
  32. <div> <?php if($a): ?> <div id='a'>ຬͨ͢</div> <?php else: ?> <div

    id=''>ຬͨ͞ͳ͍</div> <?php endif; ?> </div> http://localhost:8888/div.php
  33. HTML૊ΈࠐΈܕͷαϯϓϧ Wordpressͷ৔߹ wp-content/themes/twentysixteen/ header.php

  34. foreach <?php $numbers = array('2','3','4','5','6'); foreach($numbers as $val) { echo

    $val; }
  35. htmlspecialchars ˍ"'<>ͱ͍ͬͨHTMLͰҙຯ͋ΔจࣈΛhtmlͷදࣔܗ ࣜʹม׵͢Δ = javascriptɺෆਖ਼ͳsql࣮ߦ౳ʹΑΔηΩϡϦςΟʔϦ εΫΛճආ͢Δɻ ೖྗ͞Εͨσʔλ͸ग़ྗ͢Δ௚લʹඞͣ htmlspecialcharsΛ௨͢

  36. 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
  37. ϑΝΠϧͷಡΈࠐΈ htmlͷྔ࢈ʹ΋ศར

  38. require_once <?php require_once('header.html'); require_once('body.html'); require_once('footer.html'); http://localhost:8888/require.php

  39. ஋Λऔಘ͢Δ ೖྗϑΥʔϜ͔Βೖྗ͞Εͨ஋ $_POST http://localhost:8888/get.php?id=123456 $_GET

  40. ஋ͷऔಘ <?php echo $_GET['id']; echo $_POST['id'];

  41. ஋ͷ֬ೝ var_dump()

  42. ͜Ε͘Β͍Θ͔Ε͹OK PHPͷΦϯϥΠϯϚχϡΞϧͷॆ࣮౓͕ੌ͍ PHPͷྺ࢙ ݴޠϦϑΝϨϯε

  43. ࣮ફฤ ੈքͷਓޱϥϯΩϯάΛදࣔ͢ΔϖʔδΛ࡞ͬͯ

  44. σʔλΛ୳͢ ϓϩάϥϜͰѻ͏ͨΊʹ͸CSV΍TSVͱ͍ͬͨσʔλ ͕खؒΛল͚Δ ΤΫηϧσʔλͰ΋CSVʹ͸ग़དྷΔ http://data.worldbank.org/data-catalog/Population- ranking-table

  45. CSVΛಡΈࠐΉ ؔ਺໊͕Θ͔Βͳ͚Ε͹ͱΓ͋͑ͣݕࡧ

  46. fgetcsvͬͯͷ͕ݟ͔ͭͬͨ http://php.net/manual/ja/function.fgetcsv.php ͕Μ͹ͬͯಡΉͱΘ͔Δ Θ͔Βͳ͚Ε͹αϯϓϧΛ

  47. αϯϓϧΛ࢖ͬͯΈΔ ಈ͔ͯ͠ΈΔ http://localhost:8888/1.php csvΛࠩ͠ସ͑ΔͱɺͳΜ͔ग़ͯΔ Θ͔Βͳ͍ͱ͜Ζ͸ௐ΂Δ

  48. ௐ΂ͯΈͨΒ fopen — ϑΝΠϧ·ͨ͸ URL ΛΦʔϓϯ͢Δ whileϧʔϓ͸ɺPHPͰ࠷΋؆୯ͳλΠϓͷϧʔϓͰ͢ɻ count — ม਺ʹؚ·ΕΔ͢΂ͯͷཁૉɺ

    ͋Δ͍͸Φϒ δΣΫτʹؚ·ΕΔԿ͔ͷ਺Λ਺͑Δ fclose — Φʔϓϯ͞ΕͨϑΝΠϧϙΠϯλΛΫϩʔζ͢Δ ͜ΕΛ౿·͑ͯ
  49. ͳΜͱͳ͘Θ͔ͬͨ

  50. ৭ʑௐ੔ͯ͠ΈΑ͏ ͕࣌ؒͳ͍ͷͰׂѪͰ͢ http://localhost:8888/fgetcsv.php

  51. <table border=1> <?php ini_set('display_errors',1); $row = 1; if (($handle =

    fopen("POP.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { if($data[3]) { echo "<tr>"; echo "<td>" . htmlspecialchars($data[3],ENT_QUOTES) ."</td><td>" . htmlspecialchars($data[4],ENT_QUOTES) . "</td>"; echo "</tr>"; } } fclose($handle); } ?> </table>
  52. ׬੒ ͳΜͱͳ͘ग़དྷͦ͏ͳؾ͕͠·ͤΜ͔ʁ php.netΛݟͳ͕ΒؤுͬͯΈ·͠ΐ͏

  53. ֤஍Ͱ։࠵͞Ε͍ͯΔPHPΧ ϯϑΝϨϯε

  54. ࠙਌ձ ଞͷ։ൃऀ΍εϐʔΧʔͱ௚઀࿩͢νϟϯε!

  55. ͓קΊॻ੶ ʮ͍ͪ͹Μ΍͍͞͠PHPͷڭຊʯࢲ͕ॻ͍͍ͯ·͢ɻ ͍·ԿΛ࡞͍ͬͯΔͷ͔Λߟ͑Δ ࣗ෼Ͱߟ͑Δྗ͕ͭ͘ ਖ਼ޡදΛ͝ࢀߟʹ͍ͯͩ͘͠͞m(__)m

  56. ·ͱΊ PHPͷϚχϡΞϧΛੋඇ׆༻͠·͠ΐ͏ ग़ྗ஋ʹ஫ҙ͠·͠ΐ͏ɻ ೖ໳ॻ͸Α͘બͼ·͠ΐ͏w ා͕ͬͯ͸͍͚·ͤΜ ༐ؾΛ࣋ͬͯɺΠϯλʔωοτ্ʹϓϩάϥϜΛެ։͠ ͯΈ·͠ΐ͏ɻ

  57. ͱʹ͔͘ॻ͍ͯΈΔʂ Ҏ্

  58. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ ΧϯϑΝϨϯεΛָ͠ΜͰ͍ͩ͘͞ʂ

  59. PHPॳ৺ऀηογϣϯ ༗ݶձࣾΞϦ΢ʔϓ ദԬɹलஉ twitter,facebook @kashioka

  60. None