How to judge whether php is a number

藏色散人
Release: 2023-03-01 21:08:02
Original
11100 people have browsed it

In PHP, you can use the "is_numeric()" function to determine whether the parameter is a number. If so, it will return true. If not, it will return false. Its syntax is such as "is_numeric('abcd123') or die(' The supplied argument is not a number ');".

How to judge whether php is a number

php determines whether it is a number

There are two methods

First First: Use a function directly, is_numeric(). This function is to detect whether the parameter is a number. If so, it returns true. If not, it returns false. For example:

<?php
 is_numeric( &#39;abcd123&#39; ) or die(&#39;提供的参数不是数字&#39;);
Copy after login

Second: Use regular expression matching. If the match is successful, it is a number, and true is returned. If the match is unsuccessful, it is not a number, and false is returned.

For example:

<?php
 preg_match(&#39;/^\d+$/i&#39;, &#39;abcd123&#39;) or die(&#39;提供的数据不是数字&#39;);
Copy after login

Recommendation: "PHP Tutorial"

The above is the detailed content of How to judge whether php is a number. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!