Jump to content

[SOLVED] Checking for Empty Variables


Helminthophobe

Recommended Posts

Can I use empty() to check to see if variables actually have data? Basically I want the script or something to check to see if there is data in the variables. If there is no data, give the user some instructions on writing some data (link to a form or admin panel). If there is data, then continue with writing to the database.

 

Any help would be greatly appreciated!

Link to comment
https://forums.phpfreaks.com/topic/74734-solved-checking-for-empty-variables/
Share on other sites

I don't use the empty() function on strings, since it can return a false positive when the string consists of the a single zero character. I use

<?php
if (strlen(trim($str)) == 0) echo 'The variable $str is empty';
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.