Skip to content

Everything for WordPress, web development — and beyond

A text list into an array: PHP, JavaScript, Python, Perl, JSON, SQL

A text list into an array: PHP, JavaScript, Python, Perl, JSON, SQL

Paste a column from Excel, the output of an SQL query or simply a list one item per line — and you get a ready array with correct escaping for seven formats. Everything is computed in your browser: the list is never sent anywhere and never stored.

Drop a .txt or .csv here — the file is read locally. A column from Excel or Google Sheets can be pasted straight in.
Value handling

Works for TypeScript too. const instead of var: redefining such a variable becomes an error before the code even runs.

Paste a list above — the array will appear here.

The data never leaves your browser — the computation runs locally, with nothing sent to a server.

What exactly the tool does with each value

A line becomes one item of the array. If needed, the line can additionally be split on commas by CSV rules — then a comma inside quotes stays part of the value. After that every value is escaped, differently for each language: PHP and Perl with single quotes — exactly two characters are escaped, the backslash and the quote itself. PHP with double quotes — the dollar sign is added too, otherwise $HOME in the text would substitute a variable. Perl with double quotes — the at sign is added as well, because @list is interpolated in Perl too. JavaScript, TypeScript and Python — the backslash, the quote and control characters as escape sequences. JSON — strictly per RFC 8259, using the language's own means. SQL — the apostrophe is doubled, as the standard requires. CSV — per RFC 4180: only a field containing a comma, a quote or an edge space is quoted. A number is emitted unquoted only when it stays the same number after a round trip through Number(). A part number 007, a phone number with a leading zero, 1e5, 0x1F and an integer above 2⁵³ fail that check and stay strings.

How this differs from the old list converters

The classic arrayThis checks «is this a number» with isNaN() and escapes nothing except the quote itself. Hence four silent corruptions that only show up when the generated code runs: The path C:\Users\admin inside double quotes gives an unterminated string — the backslash starts an escape sequence there. An empty line passes isNaN() as a number and lands in the code as a bare comma: ["a", , "b"]. The part number 007 becomes an octal number in PHP and a syntax error in strict-mode JavaScript. A list copied from Windows drags an invisible carriage return along after every value. Here all four cases are handled, and the output labelled Perl really is Perl: a list in round brackets, not the array() construct, which Perl does not have.

Frequently asked questions