Jump to content

Archived

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

glenelkins

number problem

Recommended Posts

ok

a number is being sent with $_GET in the form: 150,000 i want to compare this with a variable containing a number. But when i use $tmp_price = explode(",",$_GET['pricemax']) the result is not how i would expect, ie $tmp_price[0] = 150 $tmp_price[1] = 000 ... was then going to put them together are 150000

Any ideas?

Share this post


Link to post
Share on other sites
Rather than exploding the comma and then stiching the number back together. Use str_replace:
[code=php:0]$tmp_price = $_GET['pricemax'];

// remove any commas from price max.
$price = str_replace(',', '', $tmp_price);[/code]

Share this post


Link to post
Share on other sites
What's the format that you have in the variable, is it 150,000 or just 150000?

If it's just a case of removing the delimiter, then use [url=http://uk.php.net/manual/en/function.str-replace.php]str_replace()[/url]

[code]$maxprice = str_replace(",", "", $_GET['maxprice']);[/code]

Regards
Huggie

[size=8pt][color=red][b]EDIT:[/b][/color][/size] Too slow :(!

Share this post


Link to post
Share on other sites
[quote author=glenelkins link=topic=108799.msg438016#msg438016 date=1158764475]
ok

a number is being sent with $_GET in the form: 150,000 i want to compare this with a variable containing a number. But when i use $tmp_price = explode(",",$_GET['pricemax']) the result is not how i would expect, ie $tmp_price[0] = 150 $tmp_price[1] = 000 ... was then going to put them together are 150000

Any ideas?
[/quote]

If you do want to split it up you could do this: [code]<?php
$number = explode(',',$_GET['pricemax']);
$number = join('',$number);
?>[/code]

The other option you have been showed is better though.

Share this post


Link to post
Share on other sites

×

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.