Re: [PHP] Problems converting strings with 0 to integer

2010-11-04 Thread Richard Quadling
On 3 November 2010 21:42, Alexander Holodny alexander.holo...@gmail.com wrote: To exclude unexcepted behavior in case of wrongly formated input data, it would be much better to use such type-casting method: intval(ltrim(trim($inStr), '0')) 2010/11/3, Nicholas Kell n...@monkeyknight.com: On

Re: [PHP] Problems converting strings with 0 to integer

2010-11-04 Thread Richard Quadling
On 4 November 2010 10:33, Richard Quadling rquadl...@gmail.com wrote: ?php // Create test file. $s_TabbedFilename = './test.tab'; file_put_contents($s_TabbedFilename, 0\t0002 . PHP_EOL . 4\t0004 . PHP_EOL); // Open test file. $fp_TabbedFile = fopen($s_TabbedFilename, 'rt') or

Re: [PHP] Problems converting strings with 0 to integer

2010-11-04 Thread robert mena
Hi, The core of the code is simply $fp = fopen('file.tab', 'rb'); while(!feof($fp)) { $line = fgets($fp); $data = explode(\t, $line); ... } So I try to manipulate the $data[X]. For example $data[0] is supposed to be numeric so I $n = (int) $data[0] One other thing if the second

Re: [PHP] Problems converting strings with 0 to integer

2010-11-04 Thread Richard Quadling
On 4 November 2010 15:11, robert mena robert.m...@gmail.com wrote: Hi, The core of the code is simply $fp = fopen('file.tab', 'rb'); while(!feof($fp)) {    $line = fgets($fp);    $data = explode(\t, $line);     ... } So I try to manipulate the $data[X].  For example $data[0] is supposed

Re: [PHP] Problems converting strings with 0 to integer

2010-11-04 Thread Richard Quadling
On 4 November 2010 15:31, robert mena robert.m...@gmail.com wrote: Hi Richard, I am not top posting.  I am just explaining other symptoms that may point to the cause since they may be the same and this is happening with the same file.  I'll try to get approval to release the file. Meanwhile,

[PHP] Problems converting strings with 0 to integer

2010-11-03 Thread robert mena
Hi, I have a text file (utf-8 encoded) which contains lines with numbers and text separated by \t. I need to convert the numbers that contains 0 (at left) to integers. For some reason one line that contains 0002 is casted to 0 instead of 2. Bellow the output of the cast (int) $field[0]

Re: [PHP] Problems converting strings with 0 to integer

2010-11-03 Thread Alexander Holodny
To exclude unexcepted behavior in case of wrongly formated input data, it would be much better to use such type-casting method: intval(ltrim(trim($inStr), '0')) 2010/11/3, Nicholas Kell n...@monkeyknight.com: On Nov 3, 2010, at 4:22 PM, robert mena wrote: Hi, I have a text file (utf-8

Re: [PHP] Problems converting strings with 0 to integer

2010-11-03 Thread Nicholas Kell
On Nov 3, 2010, at 4:22 PM, robert mena wrote: Hi, I have a text file (utf-8 encoded) which contains lines with numbers and text separated by \t. I need to convert the numbers that contains 0 (at left) to integers. For some reason one line that contains 0002 is casted to 0 instead