php - What does trim() actually do in this validation check? -
i'm reading php book, below phrase mean?
to eliminate leading , trailing whitespace, use trim() function.
it's being used in following condition check:
if(!empty(trim($_post['username'])) && !empty(trim($_post['email']))) { }
empty
checking make sure username , email variable not empty
! signifies not
here empty http://php.net/manual/en/function.empty.php
a variable considered empty if not exist or if value equals false. empty() not generate warning if variable not exist.
trim
removes whitespace beginning , end of stringstrip whitespace (or other characters) beginning , end of string
http://php.net/manual/en/function.trim.php
so if have string " user "
trim(" user ")
returns "user"
Comments
Post a Comment