I have the following code to check user input:
if(isset($_POST['block_name']) && !empty($_POST['block_name'])) {
$block->name = trim($_POST['block_name']);
}
But it accepts SPACE as valid input, so I changed to this:
if(isset($_POST['block_name']) && !empty($_POST['block_name']) && trim($_POST['block_name'])!='') {
$block->name = trim($_POST['block_name']);
}
I have found on web that I can use !=false as well. What is the difference and which is recommended.
''equalsfalsein a loose comparison, so there’s no real difference. Since'0'also equalsfalsethough, you may want to make your check more strict.emptyis also just checking forfalsewithout triggering an error if the variable is not set. Soisset && !emptyis redundant to begin with.Use: