Problems checking empty ()

0

I'm having problems checking a string using EMPTY (), it's the following .. If I play space on it, it "" is no longer empty .. and ends up inserting in the database the empty value, how can I solve this, what function ?

    
asked by anonymous 06.06.2014 / 00:31

1 answer

3

Remove spaces around the value before applying empty :

$valor = "   ";
$valor = trim($valor);
if(empty($valor)) {
    echo "Sim, está vazio";
}

link

The function trim removes the following characters, considered "blank", from the two ends of the string:

  • "(ASCII 32 (0x20)), a normal space.
  • "\ t" (ASCII 9 (0x09)), a tab.
  • "\ n" (ASCII 10 (0x0A)), a new line feed.
  • "\ r" (ASCII 13 (0x0D)), a carriage return.
  • "\ 0" (ASCII 0 (0x00)), the NULL byte.
  • "\ x0B" (ASCII 11 (0x0B)), a vertical tab.
06.06.2014 / 01:06