Introduction to PHP

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
时间: 2024-10-18 14:02:49

Introduction to PHP的相关文章

Spring AOP之Introduction(@DeclareParents)简介

Spring的文档上对Introduction这个概念和相关的注解@DeclareParents作了如下介绍: Introductions (known as inter-type declarations in AspectJ) enable an aspect to declare that advised objects implement a given interface, and to provide an implementation of that interface on be

Introduction and Basic concepts

1 Network Edge The device such as computers and mobiles connect to the Internet. So they are referred as end systems(who run the application programs) sitting at the edge of the Internet. And we use host and end system interchangeably, that is host=e

Introduction to Machine Learning

Chapter 1 Introduction 1.1 What Is Machine Learning? To solve a problem on a computer, we need an algorithm. An algorithm is a sequence of instructions that should be carried out to transform the input to output. For example, one can devise an algori

The basic introduction to MIX language and machine

reference: The MIX Computer, The MIX Introduction sets, The basic info storage unit in MIX computer is the byte, which stores positive values in the range of 0 to 63. In MIX, Byte only has 6 bytes, and the word Byte refer to MIX 6-byte. A MIX word is

PyQt5 Introduction and components

在开始写代码以前,对PyQt5整体大致了解一下还是有必要的.这方面的东西看看PyQt5官方给出的文档就好,下面就是我从文中截取的部分内容: Introduction PyQt5 is a set of Python bindings for v5 of the Qt application framework from The Qt Company. Qt is a set of C++ libraries and development tools that includes platform

[stm32参考手册] 1、Introduction

STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xxand STM32F107xx advanced ARM-based 32-bit MCUs 本资料覆盖范围: 这本资料提供完整的关于上述系列STM单片机的存储器和外设的使用方法.在整个文档中(除非特别说明)是把这几类单片机归于STM32F10XXX系列的. 注:STM32F10XXX是一个包含的各种不同存储器尺寸,不同封装和不同外设的微处理器家族. 其他相关资料引导: 关于订货编号.电气和物理性

〈Effective C++〉读书笔记--Introduction

Introduction 1.Learning the fundamentals of a programming language is one thing; learning how to design and implement effective programs in that language is something else entirely. 想起<重构>里面说的一句话,写出计算机能理解的代码很容易,但是写好人能理解的代码不容易 2.A declaration tells c

[转]A plain english introduction to cap theorem

Kaushik Sathupadi Programmer. Creator. Co-Founder. Dad. See all my projects and blogs → A plain english introduction to CAP Theorem You’ll often hear about the CAP theorem which specifies some kind of an upper limit when designing distributed systems

和Keyle一起学StrangeIoc &ndash; Introduction

Strange: the IoC framework for Unity Strange attractors create predictable patterns, often in chaotic systems. 在混乱的系统中创造出一个可以预测的模式 . Introduction StrangeIoc主要用于C#与Unity3d,我们已经在IOS,Web,Android项目中成功运用,他包含了如下功能,其中大部分功能都是可选的 Strange is a super-lightweigh

A.Kaw矩阵代数初步 学习笔记: 1. Introduction

“矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. 第1章课程讲义下载(PDF) Summary Matrix A matrix is a rectangular array of elements. Matrix $A$ is denoted by $$A = \begin{bmatrix}a_{11} & \cdots & a_{1n}\\ \vdots&