Basic syntax of PHP_PHP tutorial

WBOY
Release: 2016-07-13 09:45:19
Original
1074 people have browsed it

Basic syntax of PHP

Open Notepad, write the following program, and save it as hello.php:

 

 

 PHP Test

 

 

 

 $lang_name= "PHP5
";

echo "Welcome".$lang_name;

//print "Use $lang_name to print text here
";

printf("This is a display style similar to C language
");

 /*

Multi-line comments for PHP

 */

 ?>

 

This is a super test.

 

 

Based on the above small examples, let’s get to know the basic syntax of PHP:

1. How to embed PHP into HTML

It starts with "", with PHP code in the middle.

It starts with and ends with , with PHP operation code in the middle.

It starts with "", with PHP operation code in the middle. Variable embedding uses the <% echo variable%> format.

Starts with "<%" and ends with "%>", with PHP operation code in the middle. Variable embedding uses <% echo variable %>

Note: It is recommended to use the first method, and the third and fourth methods are not supported.

2. There are two ways to include require and include

The require function is usually placed in front of the PHP program. Before the program is executed, the files specified by require are read in. For the public function part of the system, you can use this method to introduce the required files.

The include function is generally placed in the processing part of process control. When the PHP program reads the include file, it will read the imported file. For example:

include(“mysql.db.class.php”);

require(“mysql.db.class.php”);

If there is a syntax error or does not exist in the file included using require, a Fatal error will be prompted and the program will be terminated immediately; while include will only display a Warning warning error, and then continue to execute the statements following the script.

3. PHP variables

PHP variables start with $, and the names are used as the distinction between variables. The naming rules are similar to those of C language, so I won’t go into details.

Initialization of regular variables: $var_name=value. For example: $num=123;$str=“phpbook”;$bool=false;$a=1.2e3;$var=null;

Initialization of array variables

 $Array name[key name]=value; For example: $animals['a']='Tiger',...; $Array name=array(Key name 1=>value1, Key name 2=>value2 ,…); $birds=array('b1'=>'Owl','b2'=>'Magpie',…);

 $Array name[]=value; For example: $mon[]='March'; $mon[]='May'; $Array name=array(value1,value2,…);For example: $arr =array('a','b','c');

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1042524.htmlTechArticleBasic syntax of PHP Open Notepad, write the following program, and save it as hello.php: html head titlePHP test/title /head body ?php $lang_name= PHP5br /; echo Welcome to use.$lang_name;...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template