php
Check empty string in PHP
September 21, 2022
In PHP, you can check if a string is empty by using the empty() function. This function takes a variable as an argument and returns TRUE if the variable is empty, FALSE otherwise.
<?php
if (empty($str)) {
echo "String is empty";
} else {
echo "String is not empty"
}
?>
To check whether a string is empty or not you can use the empty() function in PHP. As in the above code, we have passed a PHP variable named $str in empty() function if the string does not contain any value it will print 'String is empty and if it contains any character it will print 'String is not empty.
Below values are treated as empty
- 0, 0.0, "0"
- ""
- null
- false
- array()
Was this helpful?
Similar Posts
- Check if string contains a substring using PHP
- Check if file exist in PHP
- Check if item exist in array using PHP
- Check if value exist in array using in_array() PHP
- Check if a folder already created using PHP
- Calculate length of a string using strlen() function in php
- Encode html special characters and real escape string in php