Post Variables with commma

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
timclaason
Forum Commoner
Posts: 77
Joined: Tue Dec 16, 2003 9:06 am
Location: WI

Post Variables with commma

Post by timclaason »

I have a page where a user posts a dollar amount. However, I had always assumed the user would enter a dollar amount without commas, decimal places, or dollar signs...I was wrong.

How can I check there input and remove any of these rogue characters?

I am using the post method on the frontpage form. Thanks

For instance...suppose they enter: $200,000.00
I want a variable to just take the integer value: $input=200000;
Last edited by timclaason on Tue Dec 16, 2003 9:12 am, edited 2 times in total.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

not sure what you want, so heres some ideas

$_POST['money'];

$_SESSION['money';

http://uk.php.net/setcookieset cookie() function

if your having a problem with certain values not passing use a . before them

like .$_SESSION, this as i am reliably told, exits a string to go to a variable and back again, you can find complex explanations on google or here

hope this gives you some ideas
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

try this

Code: Select all

$money_without_commas = str_replace ( ",", "", $_POST['money']);
Mark
timclaason
Forum Commoner
Posts: 77
Joined: Tue Dec 16, 2003 9:06 am
Location: WI

Post by timclaason »

Will this be a problem if the user enters the value without any commas?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

no, will be fine
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

ask mysql to strip it, or javascript.

PHP can probably do it as well
Post Reply