--- Wade Behr <[EMAIL PROTECTED]> wrote:

> I'm having trouble parsing $_POST for use in my PHP form processor.
> 
> Sometimes a number will come out as a integer ($x = 1), sometimes it
> comes out as a text string ($x = "1").
> 
> Could someone please explain (or point me to an explanation of) how
> information is stored in $_POST by a form?

PHP is loosely typed.  HTTP generally has no type at all.  With PHP, a value
will take on a number or a string depending on what you do with it.  If
something looks like a string (ie data from a form via HTTP) you can cast it to
an integer by using a function like floor() or ceil().  PHP will start to look
at the string from left to right and the first character which is not part of a
number will mark a truncation point.  Hence:

floor("123abc") evaluates to 123

You can also perform arithmetic to make a conversion.  Hence, if you add zero,
PHP thinks you want to treat the value as a number.

"123.456" + 0 evaluates to 123.456

If you are expecting integer numbers, it's a good idea to perform some
scrubbing on the values to ensure that only numbers can be input.  The floor()
or ceil() functions seem to work well with this.

I note on your intro message that you started with a VIC-20.  I did as well. 
It was actually 3.5k of usable memory (upgradable to 32k) though the box said
5k since some was taken up by the video RAM and other overhead needs.  That and
the 6502 assembler were some of my early 1980s computer experiences.  I dabbled
in C and other languages but started PHP in 2000 and have found it to be
especially helpful for most of my web applications.

I have found that http://www.php.net and http://www.w3schools.com/php are two
good resources.  I also like the "cookbook" style books (from Sams and
O'Reilly) are pretty helpful for the "how do I _____ in PHP?" questions. 
Asking specific questions here (probably one per message with the code you are
trying to get working) is a good option.  We're here to help but we also like
it when you show that you have tried to help yourself.  

Sometimes when you don't tell us what you have done, we may waste time telling
you basics you already know or don't apply to your specific situation.

Also, remember to place all replies at the bottom and trim away parts of the
quoted messages which are not needed to continue the conversation.

James

Reply via email to