0
I’m having trouble checking a string using EMPTY(), it’s as follows. If I throw space into it " " it ceases to be empty.. and ends up inserting in the database the empty value, how can I solve this, which function?
0
I’m having trouble checking a string using EMPTY(), it’s as follows. If I throw space into it " " it ceases to be empty.. and ends up inserting in the database the empty value, how can I solve this, which function?
3
Remove the spaces around the value before applying the empty
:
$valor = " ";
$valor = trim($valor);
if(empty($valor)) {
echo "Sim, está vazio";
}
To function trim
removes the following "blank" characters from the two ends of the string:
Browser other questions tagged php string empty
You are not signed in. Login or sign up in order to post.
I didn’t know this function existed, it helped me a lot. Thank you!
– Vinícius Lara
I am glad you helped. Attention to the last clarification I have just made: the function
trim
affects only ends of strings, spaces in the middle are not removed.– bfavaretto
But think to me, if there is space in the middle it means that the string is no longer empty, ie the functions fulfilled with their verification duties, correct?
– Vinícius Lara
Yes @user3163662. It is the role of the function
trim
it’s not leaving empty, it’s cleaning the ends.– bfavaretto
But, there is some way even making these user checks to circumvent it and fill in empty?
– Vinícius Lara
@user3163662 Yes, there are certain Unic characters that this function does not address.
– bfavaretto