PHP determines whether data from form or URL parameters is an integer method _php tips

Source: Internet
Author: User

PHP determines whether the form or URL parameter data is an integer, and the Is_int function does not have the means to determine whether it is an integer because the form comes over a string of data from the form or URL parameter.
Is_numeric can be used to determine whether a number type, and then judge whether there is a decimal point can be judged is not an integer

if (!is_numeric ($page) | | Strpos ($page, ".")! ==false) {
echo "is not an integer";
} Else{
echo "is an integer";
}

Sometimes we need to determine whether the ID is a number method:

The method of judging number in Dedecms

$cid = Empty ($cid)? 1:intval (Preg_replace ("/[^-\d]+[^\d]/", "", $cid));

We recommend that you filter the key parameters. such as the number of regular filter

Copy Code code as follows:

if (Preg_match ("/^\d*$/", $fgid)) echo (' is a number ');
else echo (' not number ');

or use a function
Copy Code code as follows:

if (Is_numeric ($fgid)) echo (' is a number ');
else echo (' not number ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.