PHP array exporter breaks escape sequences

[expired user #10323]'s profile image [expired user #10323] posted 7 years ago in General Permalink

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's profile image ansgar posted 7 years ago Permalink

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

Code modification/commit 208723e from ansgarbecker, 7 years ago, revision 9.4.0.5134
Use double quotes for PHP values when exporting a PHP array from a grid. See http://www.heidisql.com/forum.php?t=22749
ansgar's profile image ansgar posted 7 years ago Permalink

Done in r5134

kalvaro's profile image kalvaro posted 7 years ago Permalink

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?

[expired user #10323]'s profile image [expired user #10323] posted 7 years ago Permalink

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

ansgar's profile image ansgar posted 7 years ago Permalink

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's profile image kalvaro posted 7 years ago Permalink

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's profile image ansgar posted 7 years ago Permalink

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

Code modification/commit 795e5de from ansgarbecker, 7 years ago, revision 9.4.0.5139
Remove per-row comment in PHP array grid export, which blows up the result. See http://www.heidisql.com/forum.php?t=22749#p22798
ansgar's profile image ansgar posted 7 years ago Permalink

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

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