Getting Started with PHP part1

Source: Internet
Author: User
Tags getting started with php

Some people say that PHP is the best language in the world.

It is open source free software, able to operate stably on all operating platforms, the introduction is relatively simple. For those of me who have not learned any computer language is the best starting point.

PHP now meaning :hypetext perprocessor Hypertext preprocessing language

Then learn the most basic knowledge of it first.

PHP tags

PHP has four tags, it is recommended that only one of the other three is not recommended.

<?php

?>

Common output statements from PHP

Print () Simple output statement, you can output strings, variables, expressions and other items of the value! (Cannot output complex data types such as arrays, objects, etc.)

echo Simple output statement, can output more than one data at a time, the middle is separated by commas!

Var_dump () Most of the statements used when testing the code can not only output the value of one or more data items, but also print out additional information such as the type and length of the data item! And you can output complex data types!

Print_r () only prints the elements of the group and does not print other additional information

printf is more adept at outputting "mixed products" made up of static text and other variables! There are also variable placeholders

Common variable placeholders:

%c: considers the subsequent variable to be an integer and displays the value of the ACSII code corresponding to the integer

%d: The following variable is considered an integer and displayed as a signed decimal number

%u: The following variable is considered an integer and displayed as an unsigned decimal number

%o: The following variable is considered an integer and displayed as an unsigned octal number

%x: The following variable is considered an integer and displayed as an unsigned hexadecimal number

%f: The following variable is considered a floating-point number and displayed as a floating-point number

%s: The following variable is considered a string and displayed as a string!

The biggest advantage of printf is the ability to control the format of the output variable!

PHP Declaration variables

$ variable name = variable Value

Basic syntax for variables $!

$ is just a syntax form, representing the following identifier as a variable name!

So, $ is not part of the variable name, which identifies the following string as a variable name!

Naming rules for variable names:

A naming convention that adheres to a basic identifier (consisting of letters, numbers, and underscores, which cannot begin with a number)

Case-sensitive (case-sensitive)

Can be used in Chinese, but strongly not recommended

Variable names are generally known for their names.

If a variable name consists of multiple words, there are three ways:studentname(Large hump method); Studentname (Small Hump method); Student_name (underline method, recommended)

variable variable :

There are two parts of the variable:

Variable Name variable value

The variable value is certainly variable, so the meaning of the variable variable is variable name variable, that is, the name of the variable can be replaced by another variable! So, mutable variables are also called variables!

Example: $abc = ' def '

$def = 200

echo = $ $ABC! Two $$ one of the following $ represents ABC, which also represents the value def of ABC, so the subsequent $ will disappear into $def, when $def has given a variable value, so put this value out.

Results will output 200

Delete a variable

unset (variable name)

The value of the variable

When you use one variable to assign a value to another variable, you can divide it into two situations:

1. Value passing:$ variable name 1 = $ variable name 2! Here to talk about the memory of those things, the variable value and variable name is the existence of different memory, the variable name to refer to the variable value, if the variable is assigned to another variable, then the variable value of the assigned variable is

will open up a new variable value space, and the value of two variables does not interfere with each other.

2. Reference passing:$ variable Name 1 = &$ variable Name 2! The variable values for the two variables are shared, and after the value of one variable is assigned to the value of another variable, the variable value of the assigned variable does not open a new variable value space, but instead refers to the one that is assigned to it.

Variable value space for variables

Pre-defined variables

Is that the system has been pre-defined, we can directly use it!

$_server refers to the collection of browser information and server information that the server can collect! is an array! In a real project, you need to print what you want, and access some of these elements through the data's bracket syntax!

$_get is used to receive all data submitted by the user when they fill out the form with GET Method! The data is displayed on the URL, and the transmitted capacity is less and less secure.

$_post is used to receive all data submitted by the user when they fill out the form with Get Method! The data is sent to the specified PHP file, and the transmission capacity is large and secure.

$_request contains all of the user's request data, typically post data and get data, and in fact, cookie data

Constant

Once a constant is defined, it cannot be modified or deleted! Constants are global and can be used anywhere in the script! (both inside and outside the function)!

There are two methods of defining constants:

Define (' Constant name ', ' constant value ', true)!true here indicates that the case is not case-insensitive and does not write

const constant name = constant value;

Naming rules for constants:

Constant name cannot have $

The naming rules for constant names are similar to variables and are more relaxed!

Constants have a unique way of outputting

Constant (' constant name ');

The syntax meaning of a constant:

In fact, wherever the use of constants can be replaced by variables, constants are mainly used for a value does not need to change the time, by using constants to standardize, to ensure that the data is not changed at the time of operation!

You can get current custom constants and system-predefined constants:

Get_defined_constants ()

Magic Constants

The biggest feature of Magic constants is: Start with two underscores and end with two underscores!

__file__ the path where the current footstep is located; the directory where the current footstep is __dir__; __line__ the number of rows in the current code;

__FUNCTION__ the name of the current function

__METHOD__ the name of the current method

__class__ the name of the current class

__NAMESPACE__ the name of the current namespace

Getting Started with PHP part1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.