Jump to content

trim and numbers


toddhamm

Recommended Posts

Sorry if this has already been solved. Also, I apologize if this is an amateur question...

 

I have a simple form and a script to do some validating of user data, among other tasks.

 

One part of the script is intended to verify a birthday.

 

$x = $_POST['x'];
$x = trim($x);

 

According to the php.net manual, trim() is supposed to remove whitespace before and after a string. My intent by using trim() is to determine if someone tried to skip the birthday field. I have other validation running on the value of $x, but I wanted trim() to remove whitespace.

 

However, the value of x, which in this case is expected to be numeric, such as 12 for a month, ends up being 1. This happens with any 2-digit number that a user might enter into the form field for x. The second number is always removed.

 

Any insight into why trim() removes the second number, 2 in the above example, leaving only a "1" as the value of $x, would be very greatly appreciated.

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/225517-trim-and-numbers/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.