Backend Development
PHP Tutorial
Three PHP form validation functions commonly used in project developmentThree PHP form validation functions commonly used in project development
PHP Web开发中常用的三个表单验证函数,这些都是一些经常用到的判断函数。
ISSET();——适合于检测是否存在这个参数。
定义和作用范围:用于测试一个变量是否具有值(包括0,FALSE,或者一个空字串,但不能是NULL),即:“...?fo=”也是可以通过检测,因此不适用。但如果是网址参数中并不含fo参数,就可以用isset来检测,此时isset($_GET['fo'])返回false。
不适用于:该函数不适合于验证html表单中的文本的有效方式。要检查用户输入文本是否有效,可以用empty();
empty();——最好用的一个函数。
定义和作用范围:用于检查变量是否具有空值:包括:空字串,0,null 或false,即:“...?fo=”或“...?fo=0”时,empty检测出来的结果都是ture,不适用范围:不适用于检测可为0的参数。
is_numeric();——只适用于检测数字,但假如参数名不存在,会出错,因此不适合于第一层检测。
综合示例:
<?php
ini_set("display_errors",1);
//ini_set("error_reporting",E_ALL); print_r
error_reporting(E_ALL);
$a=NULL;
if(isset($a))echo '变量$a的isset为真';
echo '<h2 id="isset的情形">isset的情形:</h2>';
if(isset($_GET['fo'])){
echo '变量\'fo\'的isset为真,变量可用';
}else{
echo '变量\'fo\'的isset为假,无变量设置';
}
echo '<h2 id="empty的情形">empty的情形:</h2>';
if(empty($_GET['fo'])){
echo '变量\'fo\'的empty为真,即空值或无效值';
}else{
echo '变量\'fo\'的empty为假,有值';
}
echo '<h2 id="is-numeric的情形">is_numeric的情形:</h2>';
if(is_numeric($_GET['fo'])){ //在参数中无fo参数时,则出错。
echo '变量\'fo\'的is_numeric为真,是数字';
}else{
echo '变量\'fo\'的is_numeric为假,不是数字';
}
echo "<h2 id="GET-fo-的情形">\$_GET['fo']=''的情形:</h2>";
if($_GET['fo']==''){ //在参数中无fo参数时,则出错。
echo 'fo无值,空的字符串';
}elseif($_GET['fo']!=''){
echo 'fo有值,不为\'\'.';
}
echo "<h2 id="GET-sex-m-的情形">\$_GET['sex']='m'的情形:</h2>";
if($_GET['sex']=='m'){ //当参数中无sex变量时就会出错。
echo '男的';
}elseif($_GET['sex']=='f'){
echo '女的';
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> </head> <body> </body> <p> <a href="?fo=Jack">传有效值</a> <a href="?fo=">传空值</a> <a href="?fo=0">传0值</a> <br /><br /> <a href="?sex=m">性别:男</a> <a href="?sex=f">性别:女</a> <br /><br /> <a href="/">清空</a> <br /><br /> <input type="text" value="<?php echo $_GET['fo']!=''?$_GET['fo']:'';?>" size="155" /> </p> </html>
相关文章:
PHP in Action: Real-World Examples and ApplicationsApr 14, 2025 am 12:19 AMPHP 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.
PHP: Creating Interactive Web Content with EaseApr 14, 2025 am 12:15 AMPHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.
PHP and Python: Comparing Two Popular Programming LanguagesApr 14, 2025 am 12:13 AMPHP 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.
The Enduring Relevance of PHP: Is It Still Alive?Apr 14, 2025 am 12:12 AMPHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.
PHP's Current Status: A Look at Web Development TrendsApr 13, 2025 am 12:20 AMPHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.
PHP vs. Other Languages: A ComparisonApr 13, 2025 am 12:19 AMPHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.
PHP vs. Python: Core Features and FunctionalityApr 13, 2025 am 12:16 AMPHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.
PHP: A Key Language for Web DevelopmentApr 13, 2025 am 12:08 AMPHP 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


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

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

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

Dreamweaver CS6
Visual web development tools






