You are here:  » Alter All Records

Support Forum



Alter All Records

Submitted by Keeop on Mon, 2008-11-10 19:57 in

Hi David,

I want to apply some global filtering to all records in all fields when I import a feed. I have added several custom fields to my products table so applying something field by field isn't really viable! Any chance you could post some code that would do the job? Basically I'm looking to strip any 'new line' and white space characters as these seem to be cropping up more and more so this should be useful for others. I know this will go in admin.php and will be along the lines of:

 $whitesp = array ("\r\n", "\r", "\n");
 $replace = array ("", "", "");
 $record = trim(str_replace($whitesp, $replace, $record));

...but I'm not too sure how to loop through all the records for each row and all fields in each row, plus if I did, I doubt it would be that efficient!

Cheers.
Keeop

Submitted by support on Tue, 2008-11-11 09:59

Hi Keeop,

You can do this right at the top of the admin__importRecordHandler function in includes/admin.php. Your code looks fine (as long as str_replace preserves key => value associations), so just insert that at the end of the global declarations after the following line:

global $filter_record;

Cheers,
David.

Submitted by Keeop on Tue, 2008-11-11 12:49

Hi David,

Can't get it to work. If I place that code where you suggested I get a duplicate error on the hash key - 'SingleDuplicate entry '6a89324e10ffbcf9a50c4d8f38eb4122' for key 2'. If I place it like this:

    foreach($record as $k => $v)
    {
      $record[trim(str_replace($whitesp, $replace, $k))] = $v;
    }

..it imports OK but doesn't strip the characters out. Help please!

Cheers.
Keeop

Submitted by support on Tue, 2008-11-11 12:53

Hello Keeop,

That version of the code would be stripping the keys rather than the values of $record. Try it like this:

    foreach($record as $k => $v)
    {
      $record[$k] = trim(str_replace($whitesp, $replace, $k));
    }

Cheers,
David.