php_first_lesson
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| php_first_lesson [2024/10/04 06:59] – appledog | php_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 12: | Line 14: | ||
| </ | </ | ||
| - | === echo.php | + | |
| + | === For the record | ||
| + | Quoting slashes. | ||
| + | |||
| + | < | ||
| + | <?php | ||
| + | echo "echo \" | ||
| + | ?> | ||
| + | </ | ||
| + | |||
| + | |||
| + | === ex.2 echo.php | ||
| Another example. | Another example. | ||
| Line 23: | Line 36: | ||
| </ | </ | ||
| - | == 2. roger.php | + | === ex.3 roger.php |
| < | < | ||
| <?php | <?php | ||
| Line 32: | Line 45: | ||
| </ | </ | ||
| + | === ex. 4 box.php | ||
| + | We can draw art. Can you make a triangle? | ||
| + | < | ||
| + | <?php | ||
| + | |||
| + | echo " | ||
| + | echo " | ||
| + | echo " | ||
| + | echo " | ||
| + | echo " | ||
| + | |||
| + | ?> | ||
| + | </ | ||
| + | |||
| + | === ex. 5 dinosaur.php | ||
| + | More art. This is fun! I think, this was a homework question (draw a dinosaur). | ||
| + | |||
| + | < | ||
| + | <?php | ||
| + | echo " | ||
| + | echo " | ||
| + | echo " | ||
| + | echo " | ||
| + | echo " __/ ( | ( |\n"; | ||
| + | echo "/ | ||
| + | ?> | ||
| + | </ | ||
| + | |||
| + | === ex. 6 triceratops.php | ||
| + | Oh, this was the homework question. Anyways, note the quoting slashes. | ||
| + | |||
| + | < | ||
| + | <?php | ||
| + | echo " | ||
| + | echo " | ||
| + | echo " | ||
| + | echo " | ||
| + | echo " | ||
| + | \\\n"; | ||
| + | echo " \\`.-~ | ||
| + | echo " (__ | / | ||
| + | echo " | ||
| + | echo " | ||
| + | echo " | ||
| + | |||
| + | |||
| + | ?> | ||
| + | </ | ||
| + | |||
| + | == 2. input with readLine() | ||
| + | Teacher and Doctor. Here is teacher.php: | ||
| + | < | ||
| + | <?php | ||
| + | |||
| + | $name = readLine(" | ||
| + | echo "Hello {$name}!\n"; | ||
| + | echo "Your new name is Teacher {$name}.\n"; | ||
| + | ?> | ||
| + | </ | ||
| + | |||
| + | and doctor.php: | ||
| + | < | ||
| + | <?php | ||
| + | |||
| + | $name = readLine(" | ||
| + | echo "Hello {$name}!\n"; | ||
| + | echo "Your new name is Dr. {$name}.\n"; | ||
| + | ?> | ||
| + | </ | ||
| + | |||
| + | == 3. decision making with if-then | ||
| + | < | ||
| + | <?php | ||
| + | |||
| + | $name = readLine(" | ||
| + | if ($name == " | ||
| + | echo "I don't like vegetables!\n"; | ||
| + | exit(); | ||
| + | } else { | ||
| + | echo "Hello {$name}!\n"; | ||
| + | echo "Your new name is Mr. {$name}.\n"; | ||
| + | } | ||
| + | ?> | ||
| + | </ | ||
php_first_lesson.1728025181.txt.gz · Last modified: 2024/10/04 06:59 by appledog
