Answer the question
In order to leave comments, you need to log in
How can I convert a string to a number?
Saved excel to csv on mac os. As a result, a file came out in windows-1251 encoding like (in Notepad ++ it is written ANSI). This file has a cell with a price of "2,568".
The problem is that I can't convert it to integer.
$price = '2568';
intval(price) //int(2)
str_replace(' ', '', $price) //string(6) "2 568"
preg_replace('/\s+/', '', $price) //string( 6) "2 568"
iconv("windows-1251", "utf-8", $price)//string(8) "2В 568"
How to get the value 2568 correctly?
Answer the question
In order to leave comments, you need to log in
1) remove spaces from number
2) either explicit conversion (int) or $string = 'xyz22' + 0 // 22
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question