distal-attribute
distal-attribute
distal-attribute
distal-attribute

PHP array exporter breaks escape sequences

Miroticey1 posted 10 months ago in General

I have a result with a HTML text column. I want to export it to a format convenient for processing. After JSON exporter failed me, I tried PHP array exporter. It outputs strings with single quotes. That breaks escape sequences, e.g. newlines.

Example output:

$foo = array(
        array( // row #0
               'BAR-BAZ',
               'hello\nworld'
        ),
);
ansgar posted 10 months ago

Oh yes, can confirm that. I guess it's the best then to use double quotes, which allows for such escape sequences.

ansgar posted 10 months ago

Done in r5134

kalvaro posted 10 months ago

Looks fine at first sight:

SELECT 'One
Two\\nThree' AS LF, 'One    Two Three\\tFour' AS TAB;
$UnknownTable = array(
    array( // row #0
        "LF" => "One\r\nTwo\\nThree",
        "TAB" => "One\tTwo\tThree\\tFour",
    ),
);

BTW, is the // row #0 part really necessary or useful?

Miroticey1 posted 10 months ago

It may come useful if you are manually editing the file and are looking for a row.

ansgar posted 10 months ago

Yes, it's intended to help the user in finding a row, but it may also blow up the code a lot if there is a huge dataset. I guess the column values are helpful enough so I should leave the "row #xyz" away?

kalvaro posted 10 months ago

I can't expect a feature to get removed just because I don't use myself but, well, when I export to PHP I always use my editor's Search and Replace feature to remove it. Whatever, let me share some random thoughts:

  1. A row count is expected to be 1-based (unlike arrays, which are often 0-based)
  2. Even if you don't care about the comment and leave it there, it gets on the way as soon as you need to edit or move items around
  3. Making it configurable brings in the usual problem of the ever growing settings controls
ansgar posted 10 months ago

I think I'll remove them for now. Also because there was noone ever asking for them - they were just an idea from me.

ansgar posted 10 months ago

r5139 removes the per-row comments for PHP array grid exports.

Please login to leave a reply, or register at first.