Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

returning zero when converting string to integer in php

Tags:

php

casting

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) "۲۹"
like image 685
AzizAhmad Avatar asked Oct 29 '25 14:10

AzizAhmad


1 Answers

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);
like image 187
Guille Acosta Avatar answered Oct 31 '25 03:10

Guille Acosta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!