Array small question
am 04.10.2007 09:44:51 von shror
I need help in a small problem,
I have created a registration form and I want my users not leave the
username empty or even enter any number of spaces because sometimes I
found that the users enter some space hits in the username and the
form is submitted, so I created an array and tried to enter the spaces
but I don't know how to make my code reject any spaces whatever their
number and I failed doing this, and what I did was that I entered in
an array the user-names I reserve for later use and space, two-spaces,
three-spaces, four-spaces, ........... but I was exhausted so please
could you tell me how to solve this and do it in a professional way.
shror
Re: Array small question
am 04.10.2007 09:48:30 von luiheidsgoeroe
On Thu, 04 Oct 2007 09:44:51 +0200, shror wrote:
> I need help in a small problem,
> I have created a registration form and I want my users not leave the
> username empty or even enter any number of spaces because sometimes I
> found that the users enter some space hits in the username and the
> form is submitted, so I created an array and tried to enter the spaces=
> but I don't know how to make my code reject any spaces whatever their
> number and I failed doing this, and what I did was that I entered in
> an array the user-names I reserve for later use and space, two-spaces,=
> three-spaces, four-spaces, ........... but I was exhausted so please
> could you tell me how to solve this and do it in a professional way.
http://www.php.net/trim
//trim whitespace surrounding the string
$string =3D trim($string);
//check for empty string
if(!empty($string)){
//do your thing
} else {
echo 'Please enter a username';
}
-- =
Rik Wasmus
Re: Array small question
am 04.10.2007 09:51:41 von shror
On Oct 4, 9:48 am, "Rik Wasmus" wrote:
> On Thu, 04 Oct 2007 09:44:51 +0200, shror wrote:
> > I need help in a small problem,
> > I have created a registration form and I want my users not leave the
> > username empty or even enter any number of spaces because sometimes I
> > found that the users enter some space hits in the username and the
> > form is submitted, so I created an array and tried to enter the spaces
> > but I don't know how to make my code reject any spaces whatever their
> > number and I failed doing this, and what I did was that I entered in
> > an array the user-names I reserve for later use and space, two-spaces,
> > three-spaces, four-spaces, ........... but I was exhausted so please
> > could you tell me how to solve this and do it in a professional way.
>
> http://www.php.net/trim
>
> //trim whitespace surrounding the string
> $string = trim($string);
> //check for empty string
> if(!empty($string)){
> //do your thing} else {
>
> echo 'Please enter a username';}
>
> --
> Rik Wasmus
thank you so much Rik for your help