I need a PHP function to be able to convert a humanly recognisable price into a price stripped of currency symbols and commas or return an error message.
I need a PHP function which uses regular expressions to ensure that data submitted via a form field is stripped of all non-numerical characters (except ".") so that what remains is a numerical "price". For example:
$123.45 becomes 123.45 ($ sign removed)
£123.45 becomes 123.45 (£ sign removed)
1,234.00 becomes 1234.00 (comma removed)
£1,234.03 becomes 1234.03 (£ sign and comma removed)
$1,234.03 becomes 1234.03 ($ sign and comma removed)
1,234.015 becomes 1234.02 (comma removed, amount rounded up to 2 decimal places)
The function must ensure that all submitted values are greater than 1.00.
The function should be robust enough to handle invalid/non-sensical data such as:
and when confronted with similar non-sensical data the function should echo a simple error message.
In short, the function should be able to convert a humanly recognisable price into a price stripped of currency symbols and commas or return an error message.
1) Complete source code of all work done.
2) Complete ownership and distribution copyrights to all work purchased.