Php determines if it is a number

Source: Internet
Author: User
We use intval to determine whether the user input is a number. this can be automatically converted to a number. if it is 0, the returned value is false, in php, to determine whether the user input is a numeric string or a numeric string, we will use is_numeric and in... we use intval to determine whether the user input is a number. this can be automatically converted to a number. if it is 0, the returned value is false, in php, we will use the is_numeric and intval functions to determine whether the user input is a numeric string or a numeric string. the instance code is as follows:

$ Num = 1; $ num1 = '1'; $ str = 'abc'; if (is_numeric ($ num) {echo $ num. 'is a numeric type';} // 1 is a numeric if (is_numeric ($ num1) {echo $ num1. 'is a numeric type';} else {echo $ num1.' not a numeric type ';}

// 1 is digital

The second example is whether it is a numeric type. it depends on whether php is a language of that type. The key is that php is a weak language type, so it will automatically convert the numeric type into numbers, the instance code is as follows:

If (intval ($ str) {echo $ str. 'is a number';} else {echo $ str. 'Not a digit';} // acd is not a number if (intval ($ num1) {echo $ num1. 'is a digit';} else {echo $ num1. 'not a digit ';} // 1 is a number


Tutorial address:

Reprinted! But please include the article address ^

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.