码迷,mamicode.com
首页 > Web开发 > 详细

Introduction to PHP

时间:2015-09-30 19:28:16      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

Part 1: HTML, Meet PHP

1. 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       <?php
11       $welcome = "Let‘s get started with PHP!";
12       echo $welcome;
13       ?>
14     </h1></div>
15     <p><strong>Generate a list:</strong>
16       <?php
17       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       <?php
27         $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       <?php
40         $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

标签:

原文地址:http://www.cnblogs.com/elewei/p/4850074.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!