Jump to content

[SOLVED] Help - i dont know how to explain it


dannybrazil

Recommended Posts

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

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...

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;
?>

Archived

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

×
×
  • Create New...

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.