I have this code, and I'm doing castto delete a character €.
cast
€
$t = "€2000"; $venc = (int)$t; echo $venc; // actually echo is 0 and i want 2000 (remove symbol)
Conclusion 0, not 2000, so the code does not work as I expect.
0
2000
What is the reason (int)$t;not echo 2000?
(int)$t;
thank
the casting procedure does not delete invalid characters, but starts from the beginning and stops when the first invalid character is reached, and then converts it to a number, in your case, the Euro character is invalid and is the first character, the result of which is 0.
check out http://www.php.net/manual/en/language.types.string.php#language.types.string.conversion
you can try (int)preg_replace('/\D/ui','',$t);
(int)preg_replace('/\D/ui','',$t);
, , , ,
(float)preg_replace('/[^0-9\.]/ui','',$t);
$t = preg_replace('/[^0-9]/i', '','€2000'); $venc = (int)$t; echo $venc;
substr
echo substr($t,3); // returns "2000"
$t = "€2000"; $venc = (int)substr($t,1); echo $venc;