answersLogoWhite

0


Best Answer

PHP provides a function called empty($var), which tests if $var is "empty." Empty has an odd definition, since the function returns true if the variable loosely equates to False. Although a zero-length string would be considered empty, so would the string "0" (among other irrelevant values).

To accept the value "0" from a field, use strlen($var). It tests the length of any variable, after casting it to a string. If this function truly equals integer zero (compared with triple-equals), the variable must be empty.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you validate empty fields in PHP?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you empty an array in PHP?

To empty an array in PHP you need to use the unset function like shown below: <?php $array = array('hello', 'hi', 'weee'); unset($array); // empty ?>


Can a php file be valid without any php code?

PHP files are HTML files with any amount of PHP intermingled into it, so the file can be empty or only contain HTML and be valid, yes.


Is php is package?

A package is a mechanism for organizing namespace, constructors, methods and fields. PHP is a technology in itself and contains quite a few packages


A criteria that searches for fields that are not empty is called?

A criteria that searches for fields that are not empty is called a "not null" criteria. This criteria is used to filter out records where a specific field does not have a null or empty value.


A criteria that searches for fields that are empty is called?

"Is Null"


Are their fields or ranches in the rainforest?

Logging companies are turning the rainforest into empty fields on a daily basis, sadly...


What are unsigned files?

files with empty or null OWNER fields


How does password appear as a string of dots?

It's a php (web script) string that turns characters into "dots" in most password fields.


Why can light travel through a vacumn?

That is because light is not an atom bumbing into the next atom (as in a sound wave), but changes in the electrical and magnetic fields. These can exist in empty space.That is because light is not an atom bumbing into the next atom (as in a sound wave), but changes in the electrical and magnetic fields. These can exist in empty space.That is because light is not an atom bumbing into the next atom (as in a sound wave), but changes in the electrical and magnetic fields. These can exist in empty space.That is because light is not an atom bumbing into the next atom (as in a sound wave), but changes in the electrical and magnetic fields. These can exist in empty space.


What all exists in a vacuum?

because the space between energy fields is empty and that is the vacuun.


Where does the trash in the city go?

after a while it is buried underground like deserts and empty fields


How do you create PHP script that receives orders for books from customers?

Have a HTML form on your site with text fields e.g. Name Address Book name or Book ID number use php to take this information and store it in a database for which you can regualry check