I’m trying to send a number from a page to another on in order to save it on my database, but when I use number_format method the number is converted to 0:
<?php
$_REQUEST["myNumber"]; // the number from the url is 25%2C8 (25,8)
// why this returns 0?
number_format (urlencode($_REQUEST["myNumber"]), 2, ".", "");
?>
I thought urlencode function was useful to convert url numbers to string numbers, where’s my fault?
You need to use urldecode function instead of urlencode if you want to decode characters. And pass ‘,’ as decimal pointer.
So your code should looks like this:
But you need to take to account that variables in $_POST\GET\REQUEST arrays is already decoded. Perhaps, your code may be even simpler: