Home Backend Development PHP Tutorial PHP basic case one: display student information card

PHP basic case one: display student information card

Nov 02, 2020 pm 10:25 PM
php

1. Requirements analysis:

# Please use PHP variables to save the student’s name, date of birth, subject and student number, and finally The student's information is output to the web page for display. Among them, when defining the student's date of birth and student number, the following two conditions must be met.

1. The date of birth is in the Gregorian calendar, and the format is YYYY-MM-DD, for example, 2003-09-08, which means you were born on September 8, 2003 in the Gregorian calendar.

2. The student number is composed of 0 plus a two-digit year, a two-digit month and date, and then a three-digit student serial number, for example, May 2012 The serial number of the first student in a certain class on the 19th is 0120519001.

3. Use the feature that PHP code can be embedded into HTML pages, write a table with 4 rows and 2 columns, embed PHP code in the table, and output the student's name, date of birth, Subject and student number.

2. Design ideas

1.Define variables to save student information and need to be defined Several variables, what are these variables?

2. To embed code into an HTML page, do you need to write a table with several rows and columns? What information do these tables output about students?

3. Knowledge Reserve

1. What is a variable?

#Variables in programs originate from mathematics and can store results or represent abstract concepts in programming languages. A simple understanding of a variable is a container that temporarily stores values. It can store numbers, text, or some complex data.

2. How to declare variables?

Because PHP is a weakly typed language, there is no need to declare variables in advance before using them. The variables will be automatically created when they are assigned a value for the first time. This reason makes the syntax of PHP and C Languages, strongly typed languages ​​such as Java are very different.

Declaring a PHP variable must use a dollar sign "$" followed by the variable name, and then use "=" to assign a value to the variable.

<span style="color: rgb(0, 0, 0);"><?php<br/>$a=1;<br/>$b=&#39;你好&#39;;<br/>?></span>
Copy after login

3. Variable naming rules

Variable name It cannot be defined arbitrarily. A valid variable name should meet the following requirements: (1) The variable must start with a $ symbol, followed by the name of the variable. $ is not part of the variable name;

(2) The variable name must start with a letter or underscore;

(3) The variable name cannot start with a number;

(4) Variable names can only contain letters (A~z), numbers (0~9) and underscores (_);

(5) What is incomprehensible with other languages ​​is , some keywords in PHP can also be used as variable names (such as $true, $for).

4、几点提示

当使用多个单词构成变量名时,可以使用下面的命名规范:

(1)下划线命名法:将构成变量名的单词以下划线分割,例如 $get_user_name、$set_user_name;

(2)驼峰式命名法(推荐使用):第一个单词全小写,后面的单词首字母小写,例如 $getUserName、$getDbInstance;

(3)帕斯卡命名法:将构成变量名的所有单词首字母大写,例如 $Name、$MyName、$GetName。

四、代码实现

<span style="color: rgb(0, 0, 0);"><?php<br/>//定义变量保存学生资料<br/>$name = &#39;王六&#39;;//保存学生的姓名<br/>$birth = &#39;2003-08-07&#39;;//保存学生的出生日期<br/>$subject = &#39;PHP&#39;;//保存学生的所属学科<br/>$snum = &#39;0150427001&#39;;//保存学生的学号<br/>?></span>
Copy after login

定义好PHP代码,编写一个4行2列的表格,在表格中嵌入PHP代码,分别输出学生的姓名、出生日期、学科以及学号。

<span style="color: rgb(0, 0, 0);"><table><br/><tr><br/><th colspan="3">展示学生资料</th><br/></tr><br/><tr><br/><td>姓  名:</td><br/><td><?php echo $name;?></td><br/></tr><br/><tr><br/><td>出生日期:</td><br/><td><?php echo $birth;?></td><br/></tr><br/><tr><br/><td>学  科:</td><br/><td><?php echo $subject;?></td><br/></tr><br/><tr><br/><td>学  号:</td><br/><td><?php echo $snum;?></td><br/></tr><br/></table></span>
Copy after login

五、效果展示

PHP basic case one: display student information card

The above is the detailed content of PHP basic case one: display student information card. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles