jerel Posted October 12, 2007 Share Posted October 12, 2007 Hello, Here is my script It's purpose is to make sure $zip is > 4 script <?php $zcount = str_split($_POST["zip"]); // where zip is passed from a form// $count = 0; foreach ($zcount as $letter) { if ($letter == '1' || $letter == '2' || $letter == '3' || $letter == '4' || $letter == '5' || $letter == '6' || $letter == '7' || $letter == '8' || $letter == '9' || $letter == '0' ) $count++; } if($count < 5) { echo "no"; } else { echo "yes"; } ?> is there an easier way? This is counting every instance of every number individually then adding them together. I actually searched to find the script that i manipulated to that on the forum here, but i figured this may be thread worthy Thanks ??? Quote Link to comment https://forums.phpfreaks.com/topic/72889-there-has-to-be-a-more-effiecient-way-character-count/ Share on other sites More sharing options...
corbin Posted October 12, 2007 Share Posted October 12, 2007 $zip = (isset($_POST['zip'])) ? $_POST['zip'] : null; if(strlen($zip) > 4 && is_numeric($zip)) { echo 'Valid ZIP entered!'; } http://php.net/strlen http://php.net/is_numeric Quote Link to comment https://forums.phpfreaks.com/topic/72889-there-has-to-be-a-more-effiecient-way-character-count/#findComment-367638 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.