User Tools

Site Tools


php_first_lesson

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
php_first_lesson [2024/10/04 07:00] appledogphp_first_lesson [2024/10/04 07:10] (current) appledog
Line 3: Line 3:
 This page is a record of what Roger and I were able to accomplish in the first lesson. Charles was there too, but he was fated to drop out because he could not type very fast. This page is a record of what Roger and I were able to accomplish in the first lesson. Charles was there too, but he was fated to drop out because he could not type very fast.
  
-== 1. Hello World+A big question could be, "Why PHP?" Well, PHP has an easy syntax and is extremely useful for web-based programming. It's a great starter, with better syntax than Python. And, why not? PHP has it's own local server, so it's easy for anyone to use. You can just use a text editor. Its oldschool! A great start for the serious. And so, we began. 
 + 
 +== 1. Hello World with echo()
 Run this. What does it do? What is ECHO? Run this. What does it do? What is ECHO?
  
Line 11: Line 13:
 ?> ?>
 </Code> </Code>
 +
 +
 +=== For the record
 +Quoting slashes.
 +
 +<Code:PHP>
 +<?php
 + echo "echo \"Hello, world!\\n\";";
 +?>
 +</Code>
 +
  
 === ex.2 echo.php === ex.2 echo.php
Line 33: Line 46:
  
 === ex. 4 box.php === ex. 4 box.php
-We can draw art. Can you make a triangle? (homework!)+We can draw art. Can you make a triangle?
  
 <Code:PHP> <Code:PHP>
Line 44: Line 57:
  echo "*****\n";  echo "*****\n";
  
 +?>
 +</Code>
 +
 +=== ex. 5 dinosaur.php
 +More art. This is fun! I think, this was a homework question (draw a dinosaur).
 +
 +<Code:PHP>
 +<?php
 + echo "               __\n";
 + echo "              / _)\n";
 + echo "     _.----._/ /\n";
 + echo "    /         /\n";
 + echo " __/ (  | (  |\n";
 + echo "/__.-'|_|--|_|\n";
 +?>
 +</Code>
 +
 +=== ex. 6 triceratops.php
 +Oh, this was the homework question. Anyways, note the quoting slashes.
 +
 +<Code:PHP>
 +<?php
 + echo "                        . - ~ ~ ~ - .\n";
 + echo "      ..          .-~               ~-.\n";
 + echo "     //    \\ `..~                      `.\n";
 + echo "    || |      }  }              /       \\  \\\n";
 + echo "(\\   \\\\ \\~^..'                         }  
 +\\\n";
 + echo " \\`.-~  o      /                    /    \\\n";
 + echo " (__          |       /        |       /      `.\n";
 + echo "  `- - ~ ~ -._|      /_ - ~ ~ ^|      /- _      `.\n";
 + echo "              |     /          |     /     ~-.     ~- _\n";
 + echo "              |_____|          |_____|         ~ - . _ _~_-_\n";
 +
 +
 +?>
 +</Code>
 +
 +== 2. input with readLine()
 +Teacher and Doctor. Here is teacher.php:
 +<Code:PHP>
 +<?php
 +
 + $name = readLine("What is your name? ");
 + echo "Hello {$name}!\n";
 + echo "Your new name is Teacher {$name}.\n";
 +?>
 +</code>
 +
 +and doctor.php:
 +<Code:PHP>
 +<?php
 +
 + $name = readLine("What is your name? ");
 + echo "Hello {$name}!\n";
 + echo "Your new name is Dr. {$name}.\n";
 +?>
 +</Code>
 +
 +== 3. decision making with if-then
 +<Code:PHP>
 +<?php
 +
 + $name = readLine("What is your name? ");
 + if ($name == "vegetables") {
 + echo "I don't like vegetables!\n";
 + exit();
 + } else {
 + echo "Hello {$name}!\n";
 + echo "Your new name is Mr. {$name}.\n";
 + }
 ?> ?>
 </Code> </Code>
php_first_lesson.1728025244.txt.gz · Last modified: 2024/10/04 07:00 by appledog

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki