How to check valid integer values using the PHP function?; In this post, I will learn you how to check whether the given veriable is an integer or not. Some time developer must need to check valid datatype for inserting into the database so this is more important in some cases.
To check given value is an integer or not we will take help of the PHP function filter_var(), This function will check and return the boolean value where the given value is a valid integer or not.
Accurate with integers this function will help us. In this function we must need to pass two arguments to check the valid integer, In The first argument we will pass the value, and in the second argument, we will pass the type of check with the valid integer. So let's take an example for deep understanding.
How To Remove HTML Tags From The PHP String
<?php // EXAMPLE 1 $int = 166; if (!filter_var($int, FILTER_VALIDATE_INT) === false) { echo("Integer is valid"); // TRUE } else { echo("Integer is not valid"); } // EXAMPLE 2 $string = '661'; if (!filter_var($string, FILTER_VALIDATE_INT) === false) { echo("Integer is valid"); } else { echo("Integer is not valid"); // FALSE }
We always thanks to you for reading our blogs.
Dharmesh Chauhan
(Swapinfoway Founder)Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us
Haresh Chauhan
(Co-Founder)We Are Also Recommending You :
- Get IP PHP Function Example - ip_info()
- could not encode content to iso-8859-1
- Simple WhatsApp Messages Send Using Chat API In PHP
- PhonePe Payment Gateway Example PHP
- How To Remove HTML Tags From The PHP String
- PHP Post Request cURL Example With Authentication
- Get Zipcode/Pincode From Latitude and Longitude PHP and Google Maps API
- Firebase Dynamic Links Shorten URL PHP Function
- Timestamp convert to datetime format
- UPI Payment Gateway Integration in PHP/Laravel