Photoshop learning experience PHP learning basics Page 1/2
WEB Application
When the client makes a request to the server program, the web server responds to the corresponding page according to the request. When the page contains a PHP script, the server will hand it over to the PHP interpreter for interpretation and execution, and then return the generated html code. Passed to the client, the client's browser interprets the html code and finally forms a page in web format.
What PHP can do
PHP is mainly used in three areas:
PHP analyzer, a WEB server and a WEB browser.
PHP syntax structure
The lexical structure of a programming language refers to a collection of basic rules that govern how to write programs in the language.
User-defined function names or class names are not case-sensitive, while variables are case-sensitive. That is to say, $name, $NAME and $NaMe are three different variables.
PHP uses semicolons to separate simple statements.
PHP comments
PHP supports C, C++ and Shell script style comments, as follows:
// Single-line comments
/* */ Multi-line comments (Note: cannot be nested)
# Script comments
~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~
Constants
A constant is a fixed value, defined with a simple identifier. Constants are case-sensitive by default.
Constant identifiers are always uppercase by convention.
define() uses this function to define constants.
String (string) constants are divided into: built-in constants and custom constants.
Constants can only contain scalar data (boolean (Boolean), integer (integer), float (floating point number))
Built-in constants: constants provided by the PHP system that will not change in value on any page
PHP_OS: Displays the operating system version of the server
PHP_VERSION: Display the PHP version
Some common system constants
__FILE__: PHP file name, if it is a reference file, the reference file name is displayed
__LINE__: The number of lines of the PHP file
TRUE FALSE: A constant indicating true or false
E_ERROR: Specify Identify the most recent errors in the code
E_WARNING: Indicate the most recent warnings in the code
E_PARSE: Analyze where there are potential problems in the code
E_NOTICE: For unusual but not necessarily wrong places
Custom constants
Use define () to define constants
define("mycomputer", "IBM");
Define constants: mycomputer The value of the constant is IBM
defined("mycomputer");
Check whether the constant is defined, return 1 if it is defined, otherwise return empty
In variable
PHP, a dollar sign ($) followed by a variable name represents a variable.Variable names are case-sensitive
< php
$var = 'Bob';
$Var = 'Joe';
echo "$var, $Var"; // Output "Bob, Joe" can be output at the same time Two variable names
$4site = 'not yet'; //Illegal variable name; starts with a number Variables cannot start with a number
$_4site = 'not yet'; $i site is = 'mansikka'; // Legal variable name; You can use Chinese but it is not recommended to use
isset($var) //Check whether the variable is defined
unset($var) //Delete the variable $var
empty($ var) //Determine whether the value of a variable exists
echo $var //Empty
>
Variable variable
A variable variable obtains the value of an ordinary variable as the variable name of the variable variable
< php
$a = 'hello'; // Ordinary variables
$$a = 'world'; // Variable variables Variable variables use the value of an ordinary variable as the name of the variable variable
echo "$a ${$a} "; //Output: hello world
echo "$a $hello"; //Output: hello world
>
Constants are different from variables
There is no dollar sign ($) in front of constants;
Constants can only be used with the define() function Definition, not through assignment statements;
Constants can be defined and accessed anywhere regardless of the rules of variable scope;
Once defined, a constant cannot be redefined or undefined;
The value of a constant can only be a scalar
Data type
Four scalar types:
Boolean
Integer
Float (float, also called double)
String (string)
Two composite types:
Array
Object (object)
Finally, there are two special types:
Resource (resource)
NULL Empty
PHP is a very weakly typed language.
In PHP, the type of a variable is usually not set by the programmer. Rather, it is determined at runtime (i.e. the value of the variable) based on the context in which the variable is used.
Example:
$str = “foo”; // String
$int = 12; boolean (gettype gets the type of the variable)
echo gettype($str); // Output string
>
Integer type
The integer value can be specified in decimal, hexadecimal or octal notation, and can be preceded by an optional symbol (- or +).
< php
$a = 1234; // Decimal number
$a = -123; // A negative number
$a = 0123; // Octal number (equal to decimal 83)
$a = 0x1a; // Ten Hexadecimal number (equal to decimal 26)
>
Floating point
Floating point number (also called float, double or real number) can be defined with any of the following syntax:
< php
$a = 1.234;
$a = 1.2e3;
$a = 7E-10;
>
String
string is a series of characters. In PHP, characters are the same as bytes, which means there are a total of 256 different character possibilities. This also implies that PHP has no native support for Unicode. (The following chapter will explain the string type in detail)
< php $str = “hello world!”; >
Boolean
This is the simplest type. boolean represents a truth value, which can be TRUE or FALSE.
When other types are converted to boolean types, the following values are considered FALSE:
Boolean value FALSE
Integer value 0 (zero)
Floating point value 0.0 (zero)
Blank string and string "0"
None Array of member variables
Object without cells (only available in PHP 4)
Special type NULL (including variables that have not been set)
All other values are considered TRUE (including any resources).
Array
Array is an important data type in PHP. A scalar can only store one data, while an array can store multiple data.
$my=array('1','2','abc','d');
Object (Object)
Object is an advanced data type that we will learn later
Resource (Resource)
Resources are composed of specialized Function to create and use
Type cast
Type cast in PHP: Add the target type enclosed in parentheses before the variable to be converted.
The allowed casts are:
(int), (integer) - Convert to integer type
(bool), (boolean) - Convert to Boolean type
(float), (double), (real) - Convert to floating point Type
(string) - Convert to string
(array) - Convert to array
(object) - Convert to object
$bar = (boolean) $foo; // $bar is a boolean
>
Current page 1/2 12Next page
The above introduces the photoshop learning experience, PHP learning basics, page 1/2, including the photoshop learning experience. I hope it will be helpful to friends who are interested in PHP tutorials.

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.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.

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

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.
