


PHP is a powerful embedded HTML scripting language that is often used by programmers as the basic language for website development. What are the basic syntaxes in PHP? In this article, I will summarize the common syntax of PHP for you.
PHP basic syntax 1, PHP script code tags
PHP script is the content included in a pair of special tags in the file, such as ASP is "", PHP can be regarded as "...?>".
However, in order to adapt to the XML standard to embed PHP into XML or XHTML, PHP does not recommend using the short format "...?>", but recommends using the long format tag " php...?>”
In addition, the PHP code block also supports the tag form of .
PHP basic syntax 2, PHP instruction delimiter
Each statement in PHP needs to be separated by a semicolon ";", but for the PHP end mark "?> ;", because it automatically implies a semicolon, so there is no need to append a semicolon.
So, the format of a PHP script can be as follows:
<?php //注意最后一行可以没有分号 ?>
PHP basic syntax three, PHP comments
PHP multi-line comments use ""
Use "#" or "//" for single-line comments
PHP basic syntax 4, PHP output
Use "" quickly output a single line, or use ""
Use "echo()" or "print directly in PHP ()", for example:
< ?php echo "a"; echo (b); echo ("c"); echo d; ?>
will be output as "abcd", and all the above four types can be output normally.
But this is impossible in ASP, especially when echo "a"; and echo d; are both output as strings themselves. This requires understanding PHP variable definitions.
PHP basic syntax 5, PHP variables
Like ASP, PHP variables do not need to be defined first and can be used directly. The type of the variable is automatically generated when assigning a value.
Various variables in PHP are distinguished by adding "$" before the variable name.
< ?php $a="123"; echo a; echo $a; ?>
The input is “a123”
PHP basic syntax six, the difference between single quotes and double quotes in PHP
< ?php $a="123"; echo "$a"; echo '$a'; ?>
The output is “123” $a", where echo "$a" outputs the value of variable a, and echo '$a' outputs the string itself in single quotes.
< ?php $a="123"; echo "$a'$a'"; ?>
The output is "123'123'" not "123$a". Although it is '$a', the variable placed under double quotes is still replaced.
So, it can be concluded that as long as the variables are in double quotes, they will be replaced; while those in single quotes will not be replaced.
If the content in double quotes needs to be escaped, use the "" prefix, such as "", "$", """. So to enter "123$a", it is
< ?php $a="123"; echo "$a$a"; ?>
Another example:
< ?php $a="123"; echo "$a$a""; ?>
The output is "123$a"".
What you need to pay attention to when transferring from ASP to PHP is:
1. It is easy to forget to write the separator comma ";".
2, definition and use of variables.
3, the usage of single quotes and double quotes.
Related recommendations:
php A complete list of the most commonly used built-in functions
The above is the detailed content of What are the basic syntax of php? Introduction to basic usage of PHP. For more information, please follow other related articles on the PHP Chinese website!

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor
