標籤:
Part 1: HTML, Meet PHP1. PHP in action
PHP is a programming language that can do all sorts of things:
- evaluate form data sent from a browser,
- build custom web content to serve the browser
- talk to a database
- send and receive cookies (little packets of data that your browser uses to remember things)
Check out the code in the editor. Looks familiar, doesn‘t it? That‘s because a lot of it is regular old HTML! The PHP code is written in the <?php and ?> . See how it generates numbers, creates lists, and adds text directly to your webpage?
index.php
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <link type=‘text/css‘ rel=‘stylesheet‘ href=‘style.css‘/> 5 <title>PHP!</title> 6 </head> 7 <body> 8 <img src="http://i1061.photobucket.com/albums/t480/ericqweinstein/php-logo_zps408c82d7.png"/> 9 <div class="header"><h1>10 <?php11 $welcome = "Let‘s get started with PHP!";12 echo $welcome;13 ?>14 </h1></div>15 <p><strong>Generate a list:</strong>16 <?php17 for ($number = 1; $number <= 10; $number++) {18 if ($number <= 9) {19 echo $number . ", ";20 } else {21 echo $number . "!";22 }23 }; ?>24 </p>25 <p><strong>Things you can do:</strong>26 <?php27 $things = array("Talk to databases",28 "Send cookies", "Evaluate form data",29 "Build dynamic webpages");30 foreach ($things as $thing) {31 echo "<li>$thing</li>";32 }33 34 unset($thing);35 ?>36 </p>37 <p><strong>This jumbled sentence will change every time you click Submit!<strong></p>38 <p>39 <?php40 $words = array("the ", "quick ", "brown ", "fox ",41 "jumped ", "over ", "the ", "lazy ", "dog ");42 shuffle($words);43 foreach ($words as $word) {44 echo $word;45 };46 47 unset($word);48 ?>49 </p>50 </body>51 </html
Introduction to PHP