Zend - The PHP Company




Text

Add Code


Check for truly blank strings  

Type: code fragment
Added by: marcus1
Entered: 16/07/2000
Last modified: 08/12/1999
Rating: ** (6 votes)
Views: 6956
isBlank is a function to determine if a string is really empty or not.


<?php

/* 

This function tests to make sure a string is _really_ non-null.  It
accepts one argument:
        $string - the string to be tested

It returns true if the string is really a null string, and false
otherwise.

*/
function isBlank ($string) {
        if (
$string == "") return true;
        for (
$i 0$i strlen($string); $i++) {
                
$c substr($string$i1);
                if ((
$c != "r") && ($c != " ") && ($c != "n") && ($c != "t")) {
                        return 
false;
                }
        }
        return 
true;
}
?>


Usage Example


$string = " n"

if (isBlank($string)) {
   echo "Blank!n";
else {
    echo "Validn";
}

/* Result:
  Blank!
*/
   


Rate This Script





Search



This Category All Categories