mr-data-converter icon indicating copy to clipboard operation
mr-data-converter copied to clipboard

PHP: Numbers that are a string

Open ursbraem opened this issue 11 years ago • 6 comments

Hi!

First let me say that Mr. Data Converter is super awesome. Thanks a lot!

I've had an issue when pasting the following code from Excel:

Tag/e Monat/e Jahr Veranstaltung Organisator Referatstitel Ort 14-15 8 2007 Event Stadt Zürich Title Zürich

The first value is a string. But it looks like a calculation. What Mr. D gives back is:

array("val0"=>14-15,"val1"=>8,"val2"=>2007,"val3"=>"Zürcher Ferienpass","val4"=>"Stadt Zürich","val5"=>"Dein Handy und die Technik","val6"=>"Zürich"),

And what PHP gives back for $row['val0'] is: -1 because it does the math for 14-15.

Would it therefore make sense to be able to add double quotes around each value, also numeric ones?

ursbraem avatar Sep 26 '12 19:09 ursbraem

Same issue here.

mbbender avatar Nov 13 '12 23:11 mbbender

[Update] Current situation in the Demo:

  • Numbers that contain special chars like '.' or '-' are quoted, simple numbers are not. Just like @ursbraem, I believe that it's way better to quote everything. But anyway...might be OK to close this issue if you like to.

Abromeit avatar Oct 10 '13 11:10 Abromeit

There is another scenario to consider: postal codes. For example, I'm converting a sheet with a postal code column that contains the value "0800" (a postal code in Australia). The converted JSON property is "postcode":0800, which is invalid. Please provide an option to quote all values, even when the string is all numbers.

thdoan avatar Nov 24 '14 09:11 thdoan

@thdoan In my situation, UPC code starts with zeros some times. I forked a copy and commented out a few lines. in js/CSVParser.js

  //---------------------------------------
  // UTILS
  //---------------------------------------

  isNumber: function(string) {
//  if( (string == null) || isNaN( new Number(string) ) ) {
      return false;
    },
//   return true;
 // },

You could probably deleted the whole thing but basically it returns false all the time so it never tries to parser into numbers/int

I would add an option to turn this off and on though. But this was a quick and easy way to change the tool to get the same results.

victor-t avatar Jan 25 '17 23:01 victor-t

@victor-t I fixed this long back, along with a few other enhancements in my fork.

thdoan avatar Feb 08 '17 11:02 thdoan

@thdoan I figured but just incase ;) i'll take a look at your fork cause i just recently started using this.

victor-t avatar Feb 08 '17 17:02 victor-t