php
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePHP
PHP
A popular specific-purpose scripting language that is especially suited to web development.
一种广受欢迎的专用脚本语言,尤其适用于Web开发。
When to Use
适用场景
- Server-side web development
- WordPress / CMS development
- Content-heavy sites
- Rapid prototyping
- 服务器端Web开发
- WordPress / CMS开发
- 内容密集型网站
- 快速原型开发
Quick Start
快速开始
php
<?php
$name = "World";
echo "Hello, $name!";
$colors = ["red", "green", "blue"];
foreach ($colors as $color) {
echo $color . "<br>";
}
?>php
<?php
$name = "World";
echo "Hello, $name!";
$colors = ["red", "green", "blue"];
foreach ($colors as $color) {
echo $color . "<br>";
}
?>Core Concepts
核心概念
Arrays
数组
PHP arrays are versatile (serve as lists, maps, stacks, etc.).
php
$user = [
"id" => 1,
"name" => "Foo"
];PHP数组用途广泛(可作为列表、映射、栈等使用)。
php
$user = [
"id" => 1,
"name" => "Foo"
];Superglobals
超全局变量
Built-in variables available in all scopes (, , ).
$_GET$_POST$_SESSION在所有作用域中都可用的内置变量(、、)。
$_GET$_POST$_SESSIONOOP
面向对象编程(OOP)
PHP 8+ has robust object-oriented features including properties, attributes, and match expressions.
PHP 8+具备强大的面向对象特性,包括属性、attributes和匹配表达式。
Best Practices
最佳实践
Do:
- Use Composer for dependency management
- Type hint function arguments and return types
- Use PDO for database access (prepared statements)
- Follow PSR standards (PSR-12)
Don't:
- Use functions (deprecated/removed)
mysql_ - Trust user input (sanitize/validate)
- leave on in production
display_errors
建议:
- 使用Composer进行依赖管理
- 为函数参数和返回值添加类型提示
- 使用PDO进行数据库访问(预处理语句)
- 遵循PSR标准(PSR-12)
不建议:
- 使用系列函数(已废弃/移除)
mysql_ - 信任用户输入(需进行过滤/验证)
- 在生产环境中开启
display_errors