我们用intval来判断用户输入的信息是否为数字,这个可以自动转换成数字,如果是0,返回的值也是假的,在php判断用户输入的是否为数字型或是否为数字型字符串,我们会用到is_numeric与intval函数来处理.实例代码如下:
$num = 1; $num1 ='1'; $str ='abc'; if( is_numeric( $num ) ) { echo $num.'是数字型'; } //1是数字型 if( is_numeric( $num1) ) { echo $num1.'是数字型'; } else { echo $num1.'不是数字型'; }
//1是数字型
第二个实例为看还是数字型呢,这要看php是那类型的语言了,关键是php是弱语言型,所以就会自动把数字型字符转换成数字了,实例代码如下:
if( intval( $str ) ) { echo $str.'是数字'; } else { echo $str.'不是数字'; } //acd不是数字 if( intval( $num1 ) ) { echo $num1.'是数字'; } else { echo $num1.'不是数字'; } //1是数字

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

SublimeText3 Chinese version
Chinese version, very easy to use

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.

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

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
