when I want to convert a numeric string variable into integer in php, the return value is zero. I used all ways to convert it! such as:(int), (integer), intval(), settype(), eval(), etc. all of them return zero!
var_dump($myVariable)
prints the following:
string(4) "۲۹"
I found it! before converting string to integer, I should convert arabic number to english using this function:
function convert($string) {
$persian = array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹');
$num = range(0, 9);
return str_replace($persian, $num, $string);
}
now, I can convert it! thanks from kingkero.
Other common error is trying to cast a string variable that contains numbers but starts with zero, i.e.:
string(5) " 358"
To solve this, I used a filter_var sanitizing number INT doing this:
$myVariable = filter_var($myVariable, FILTER_SANITIZE_NUMBER_INT);