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 :
- Match Function Php 8
- Zaakpay Payment gateway Integration Tutorial PHP
- Firebase Dynamic Links Shorten URL PHP Function
- Php Questions for Interview
- Upayments Gateway Integration PHP - Laravel
- Error : Trying To Get Property Of ID Non-Object All Possible Solution Guideline In Laravel - PHP
- How to Make/Create/Write JSON File Using PHP Array In Laravel - PHP
- How To Remove HTML Tags From The PHP String
- Get Zipcode/Pincode From Latitude and Longitude PHP and Google Maps API
- PHP Post Request cURL Example With Authentication