PHP basic case one: display student information card
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='你好';<br/>?></span>
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 = '王六';//保存学生的姓名<br/>$birth = '2003-08-07';//保存学生的出生日期<br/>$subject = 'PHP';//保存学生的所属学科<br/>$snum = '0150427001';//保存学生的学号<br/>?></span>
定义好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>
五、效果展示
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.
