note 53926 modified in types.comparisons by philip

From: Date: Wed, 14 Dec 2005 02:42:00 +0000
Subject: note 53926 modified in types.comparisons by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-100103@lists.php.net to get a copy of this message
<?php if (strlen($_POST['var']) > 0) { // form value is ok } ?> When working with HTML forms this a good way to: (A) let "0" post values through like select or radio values that correspond to array keys or checkbox booleans that would return FALSE with empty(), and; (B) screen out $x = "" values, that would return TRUE with isset()! Because HTML forms post values as strings, this is a good way to test variables! [[Editor Note: This will create a PHP Error of level E_NOTICE if the checked variable (in this case $_POST['var']) is undefined. It may be used after (in conjuection with) isset() to prevent this.]] --was-- <?php if (strlen($_POST['var']) > 0) { // form value is ok } ?> When working with HTML forms this a good way to: (A) let "0" post values through like select or radio values that correspond to array keys or checkbox booleans that would return FALSE with empty(), and; (B) screen out $x = "" values, that would return TRUE with isset()! Because HTML forms post values as strings, this is a good way to test variables! http://php.net/manual/en/types.comparisons.php

« previous php.notes (#100103) next »