How to test for empty strings in PHP

//------------------------------------------------//
// How to test for empty strings in PHP
//------------------------------------------------//
// http://www.texelate.co.uk/blog/how-to-test-for-empty-strings-in-php/
function strictEmpty($var) {

 // Delete this line if you want space(s) to count as not empty
 $var = trim($var);

 if(isset($var) === true && $var !== '') {
 // It's empty
 }
 else {
 // It's not empty
 }
}

Revisions

Tags: ,

No comments yet.

Leave a Reply