PHP empty() string function

PHP empty() function

The PHP emplty() function used to check whether the string is empty or not.

In PHP the empty() function return true if the variable has empty or zero value and it return false if string has non-empty or non-zero value.

PHP empty() sunction syntax:

empty(“string”);

PHP example of empty() function :

Here, we take an example of empty() function. create a php form with one textbox with a submit button control. we do here when user click the submit button if the textbox value is blank so the result will be error message like “please enter username !!”, or if already entered some value then click submit button this time result will be “welcome user” on screen.

When we run above php example then the result will be like :

When we input “meera” string in textbox the result will be “welcome meera” but if we enter “0″ digit value it will return error message “please enter username” because the for the empty() function digit zero(0) and empty string both are same.

PHP empty() function example

PHP empty() function example

In above php example we use empty() function to check whether textbox value empty of not. Here, we use isset() function to confirm the submit1 button is clicked or not. The php code execute if only the submit1 button is clicked.

Leave a Reply

Your email address will not be published. Required fields are marked *

3 + 4 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">