Home > Archive > PHP Language > April 2007 > $ sign input
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Can anyone help? I've got a text input box where the user occasionally
enters $ sign. For example they might enter $90,000 for a dollar amount.
The problem i'm having is that my php script is seeing this as a variable.
I'm not sure how to get around this problem.
Art
| |
| Hendri Kurniawan 2007-04-20, 3:57 am |
| Art wrote:
> Can anyone help? I've got a text input box where the user occasionally
> enters $ sign. For example they might enter $90,000 for a dollar amount.
> The problem i'm having is that my php script is seeing this as a variable.
> I'm not sure how to get around this problem.
>
> Art
>
>
addslashes will do the job ... me thinks
Hendri
| |
|
| On Thu, 19 Apr 2007 20:42:27 -0400, "Art" <c_art@bellsouth.net> wrote:
>Can anyone help? I've got a text input box where the user occasionally
>enters $ sign. For example they might enter $90,000 for a dollar amount.
>The problem i'm having is that my php script is seeing this as a variable.
>I'm not sure how to get around this problem.
>
>Art
>
what I do is filter out the $ , then insert just the number with a simple function
function clear_currency($cca){
$ccb = array("$","," );
$ccc = str_replace($ccb, "",$cca );
return $ccc;
}
so you post the form and clean the money var
$money = clear_currency($_POST['moneyVar']);
then you do what you like with the $money variable
If you want the form to be 'sticky' to reshow the client the number in currency format,
you do it this way
<input type="text" name="moneyVar" value="<?= "\$". number_format($money); ?>" >
that should do it.
| |
|
|
"Gleep" <Gleep@Gleep.com> wrote in message
news:gdcg23pc56j07od8dti04nv75g1lefqa8p@
4ax.com...
> On Thu, 19 Apr 2007 20:42:27 -0400, "Art" <c_art@bellsouth.net> wrote:
>
>
>
> what I do is filter out the $ , then insert just the number with a
> simple function
>
> function clear_currency($cca){
> $ccb = array("$","," );
> $ccc = str_replace($ccb, "",$cca );
> return $ccc;
> }
>
>
> so you post the form and clean the money var
>
> $money = clear_currency($_POST['moneyVar']);
>
> then you do what you like with the $money variable
>
>
> If you want the form to be 'sticky' to reshow the client the number in
> currency format,
> you do it this way
>
> <input type="text" name="moneyVar" value="<?= "\$".
> number_format($money); ?>" >
>
> that should do it.
"Gleep" <Gleep@Gleep.com> wrote :
> function clear_currency($cca){
> $ccb = array("$","," );
> $ccc = str_replace($ccb, "",$cca );
> return $ccc;
> }
Perhaps, you could use a slight variation on the theme...
function clear_currency($cca)
{
$ccc = $cca;
$ccc = str_replace("\$", "[USD] ",$ccc);
$ccc = str_replace("£", "[GBP] ",$ccc);
return $ccc;
}
| |
| ZeldorBlat 2007-04-21, 3:57 am |
| On Apr 19, 8:42 pm, "Art" <c...@bellsouth.net> wrote:
> Can anyone help? I've got a text input box where the user occasionally
> enters $ sign. For example they might enter $90,000 for a dollar amount.
> The problem i'm having is that my php script is seeing this as a variable.
> I'm not sure how to get around this problem.
>
> Art
How are you using the value of the text box that PHP would parse it as
a variable? If you have a $ in a string it shouldn't make any
difference.
| |
|
| On 20 Apr 2007 06:03:22 -0700, ZeldorBlat <zeldorblat@gmail.com> wrote:
>On Apr 19, 8:42 pm, "Art" <c...@bellsouth.net> wrote:
>
>How are you using the value of the text box that PHP would parse it as
>a variable? If you have a $ in a string it shouldn't make any
>difference.
I'm not sure I understand your question, let me explain this way. I'm trying to remove extraneous
characters from the dollar amount. Someone types in $90,000 US I only want to save 90000
in the database. If the programmer set up a field in a table called amount and set it to integer -
then the db will be expecting a numbers only. From there one could determine sums or averages or
some other type of calculation from the db. Then when it's time to display a number in currency
format, you would reformat the 90000 to display as $90,000 US or whatever you want.
I don't think it's a wise decision to save the amount as \$90,000 US as string format,
should be just the number alone, because you can do more with it later.
| |
|
| Thank you, if i'm posting the form wouldn't it contain all the various text
input and have the effect of overwriting my individual post on just that
variable?
For example, if i had from a form the variables a,b,c and d, when i do a
post i thought a,b,c,d would be posted with their content. So if a had
$90,000 then this would be posted
If i then post "a" individually using the function you outlined, with the
clean string, wouldn't it just get overwritten by the form post?
Is it just a matter of how the post are arranged sequentially, by that i
mean will one post overwrite another?
Please excuse my ignorance, i'm new to php programming.
Thanks
Art
"Sean" <sean.anderson@[nospam]oakleafgroup.biz> wrote in message
news:1177059544.192629@kestrel.skynet.co.uk...
>
> "Gleep" <Gleep@Gleep.com> wrote in message
> news:gdcg23pc56j07od8dti04nv75g1lefqa8p@
4ax.com...
>
>
> "Gleep" <Gleep@Gleep.com> wrote :
>
>
> Perhaps, you could use a slight variation on the theme...
>
> function clear_currency($cca)
> {
> $ccc = $cca;
> $ccc = str_replace("\$", "[USD] ",$ccc);
> $ccc = str_replace("£", "[GBP] ",$ccc);
> return $ccc;
> }
>
>
>
| |
| Christoph Burschka 2007-04-21, 6:57 pm |
| Art wrote:
> Can anyone help? I've got a text input box where the user occasionally
> enters $ sign. For example they might enter $90,000 for a dollar amount.
> The problem i'm having is that my php script is seeing this as a variable.
> I'm not sure how to get around this problem.
>
> Art
>
>
Use single quotes instead of double quotes to wrap the string. Inside single
quotes, dollar signs are not parsed as variables.
Example:
$hello = "HELLO";
print "The variable is named $hello";
> The variable is named HELLO
print 'The variable is named $hello';
> The variable is named $hello
--
Christoph Burschka <christoph.burschka@rwth-aachen.de>
Math.-Techn. Assistent i.A.
-------------------------------------------------
RWTH Aachen
Rechen- und Kommunikationszentrum
Dienstgebäude Seffenter Weg 23
52074 Aachen
| |
|
| On 20 Apr, 04:32, Gleep <G...@Gleep.com> wrote:
>
> what I do is filter out the $ , then insert just the number with a simple function
>
> function clear_currency($cca){
> $ccb = array("$","," );
> $ccc = str_replace($ccb, "",$cca );
> return $ccc;
>
> }
It's probably a much better idea to filter all the non-numerics out.
use filter() or the OWASP toolkit
C.
| |
|
| ZeldorBlat wrote:
> On Apr 19, 8:42 pm, "Art" <c...@bellsouth.net> wrote:
>
> How are you using the value of the text box that PHP would parse it as
> a variable? If you have a $ in a string it shouldn't make any
> difference.
....and if it does, you probably have an immense security leak at the
moment....
Indeed, dollar signs in string should not be any problem, ever. In this
case converting it to a number is best though.
--
Rik Wasmus
|
|
|
|
|