I already know what I can use empty($valor)
to determine if my variable is empty. The dangerous thing about this is that if someone sends pure blank characters to the input (with the space bar) it will assume that it is not empty.
Then
how can I detect if only blank characters come in an input?
In addition to the function you mention
empty()
, you can use the facttrim()
that it is intended for:Example: We have this string that has empty spaces inside it and with the empty() function it tells us that it has values even though these are just blank spaces
The above returns 1.
Now if we combine the use of
empty
with the use oftrim()
as follows:It returns us 0 with which it indicates that if it is empty
The above is valid even if we pass a value in text with blank spaces at the beginning, since they are eliminated:
returns us 1
trim()
https://www.php.net/manual/es/function.trim.php