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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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