dannybrazil Posted July 27, 2009 Share Posted July 27, 2009 Hello I have a form that is sending a "price" variable to my database in the format of : R$100.000,00 (or simillar) what i want is to know if its possible to "remove" all the signs from the price in order to facilitate the price search after (it wont work with the 'between' command) what i want to know is how to make this input R$100.000,00 to be sent to the database like that 100000(no signs like R$ / . / , ) Thanks Danny Link to comment https://forums.phpfreaks.com/topic/167629-solved-help-i-dont-know-how-to-explain-it/ Share on other sites More sharing options...
JonnoTheDev Posted July 27, 2009 Share Posted July 27, 2009 try $price = "R$100.000,00"; $price = number_format(str_replace("R$", "", $price), 0, '', ''); print $price; Link to comment https://forums.phpfreaks.com/topic/167629-solved-help-i-dont-know-how-to-explain-it/#findComment-884002 Share on other sites More sharing options...
zq29 Posted July 27, 2009 Share Posted July 27, 2009 Alternatively, if the input is not always the same, you could do something like this: <?php $str = "R$100.000,00"; function numbers_only($in) { $out = ""; for($i=0; $i<strlen($in); $i++) if(is_numeric($in{$i})) $out .= $in{$i}; return $out; } echo numbers_only($str); ?> Off the top of my head, I can't think of a built-in function that can do this... Link to comment https://forums.phpfreaks.com/topic/167629-solved-help-i-dont-know-how-to-explain-it/#findComment-884006 Share on other sites More sharing options...
JonnoTheDev Posted July 27, 2009 Share Posted July 27, 2009 Off the top of my head, I can't think of a built-in function that can do this... Thats a bit long winded SemiApocalyptic. To remove anything bar a number you could simply use <?php $string = 'R$100.000,00'; $result = preg_replace('/[^0-9]+/', '', $string); print $result; ?> Link to comment https://forums.phpfreaks.com/topic/167629-solved-help-i-dont-know-how-to-explain-it/#findComment-884012 Share on other sites More sharing options...
zq29 Posted July 27, 2009 Share Posted July 27, 2009 Thats a bit long winded SemiApocalyptic. To remove anything bar a number you could simply use Good point. Link to comment https://forums.phpfreaks.com/topic/167629-solved-help-i-dont-know-how-to-explain-it/#findComment-884014 Share on other sites More sharing options...
dannybrazil Posted July 27, 2009 Author Share Posted July 27, 2009 wow that was fast...Thanks guys. Danny Link to comment https://forums.phpfreaks.com/topic/167629-solved-help-i-dont-know-how-to-explain-it/#findComment-884024 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.