前端必学之PHP语法基础_PHP
写在前面的话
PHP是一种创建动态交互性站点的强有力的服务器端脚本语言。PHP能够包含文本、HTML、CSS以及PHP代码,在服务器上执行,结果以纯文本返回浏览器
代码标识
PHP代码以结尾,且可以放置在文档中的任何位置
<?php // ?>
PHP语句以分号(;)结尾,PHP代码块的关闭标签也会自动表明分号
<?php echo "Hello World!"; ?>
注释
PHP支持三种注释,包括两种单行注释和一种多行注释
<?php // 这是单行注释 #这也是单行注释 /* 这是多行注释块 它横跨多行 */ ?>
输出
在PHP中,有两种基本的输出方法:echo和print
print只能输出一个字符串,并始终返回1
echo能够输出一个以上的字符串,echo比print稍快,因为它不返回任何值
脚本之间友情提醒大家需要注意点:echo和print都是语言结构,有无括号都可以使用echo或echo(),以及print或print(),且echo或print关键字与字符串之间至少要有一个空格
<?php echo "<h2 id="PHP-is-fun">PHP is fun!</h2>"; echo "Hello world!<br>"; echo "I'm about to learn PHP!<br>"; echo "This", " string", " was", " made", " with multiple parameters."; ?> <?php print "<h2 id="PHP-is-fun">PHP is fun!</h2>"; print "Hello world!<br>"; print "I'm about to learn PHP!<br>"; //该行出错,因为print只能输出1个字符串 print "This", " string", " was", " made", " with multiple parameters."; ?>
计算表达式
不同于HTML和CSS,在PHP中可以写计算表达式
<?php //36 echo 12*3; ?>
大小写
在PHP中,所有用户定义的函数、类和关键词都对大小写不敏感,但所有变量都对大小写敏感
<?php //Hello World! ECHO "Hello World!<br>"; //Hello World! echo "Hello World!<br>"; //Hello World! EcHo "Hello World!<br>"; ?>
友情提醒大家需要注意点: .号代表字符串连接,在其他的编程语言中,一般用+号
<?php $color="red"; //My car is red echo "My car is " . $color . "<br>"; //My house is echo "My house is " . $COLOR . "<br>"; //My boat is echo "My boat is " . $coLOR . "<br>"; ?>
以上内容是小编给大家分享的前端必学之PHP语法基础,希望对大家有所帮助,同时感谢大家一直以来对网站的支持,同时祝大家元旦快乐。!

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



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo
