Hey gang,
Pretty new (3rd week) to php and coding in general, I run a small appraisal business, and I'm working on creating a php application for tracking our orders. Been struggling with this for about an hour and just wanted some critique now that I have it working. The idea is to take a session variable pass it to this function and return the number in a $###,### fashion. Was having trouble figuring out how to use the money_format function correctly. Here it is let me know what you think.
example: user enters $125,000.00 returns $125,000
user enters 125000 returns $125,000
user enters 1,25,000.00 returns $125,000
The only thing that will break it (that I have found) is if a . is entered instead of ,
maybe this will be useful to someone else as well 🙂
#####################################################################
#
# filename: formatestvalue.inc.php
#
# purpose: include to strip all tags from estimated value,
# format and return the value in a $###,### fashion.
#
#####################################################################
function format_estvalue($estimatedvalue){
$est_explode_array = explode(".", $estimatedvalue);
$est_replace_var = preg_replace("/[^0-9]/","",$est_explode_array[0]);
$num_form_est = number_format($est_replace_var);
$dollar_sign = "\$";
$num_done = $dollar_sign.$num_form_est;
return $num_done;
}