You are here:  » Removing zero padding from feed


Removing zero padding from feed

Submitted by ChrisNBC on Tue, 2014-01-21 10:24 in

Hi David,

Hope all is going well.

I have one merchant feed where the fields containing some numeric values are zero padded. I'm sure this must have come up before but I searched the forum and couldn't see anything. I wondered if you could tell me if there is a simple way to strip the zero padding prefixing the numeric values?

Thanks in advance.

Regards
Chris

Submitted by support on Tue, 2014-01-21 10:40

Hi Chris,

Here's code for a Trim filter to add to includes/filter.php. trim() will strip white space by default, to include zeros in the trim enter "0" (without the quotes) in the Additional Characters box on the configuration page for the filter.

  /*************************************************/
  /* trim */
  /*************************************************/
  $filter_names["trim"] = "Trim";
  function filter_trimConfigure($filter_data)
  {
    print "Additional Characters:<br />";
    print "<input type='text' size='40' name='chars' value='".widget_safe($filter_data["chars"])."' />";
    widget_errorGet("text");
  }
  function filter_trimValidate($filter_data)
  {
  }
  function filter_trimExec($filter_data,$text)
  {
    return trim($text,$filter_data["chars"]);
  }

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Tue, 2014-01-21 12:41

Hi David,

Thanks for the quick response. I added the attached filter and specified '0' in the Additional Characters box. There is a slight problem in that some of the numeric values contain zeros so where the field is 000000001000 the value is truncated to 1. Is there a way to force the filter to only strip leading digits?

Thanks in advance.

Regards
Chris

Submitted by support on Tue, 2014-01-21 16:03

Hi Chris,

If you replace the following line:

    return trim($text,$filter_data["chars"]);

...with:

    return ltrim($text,$filter_data["chars"]);

...that will left trim only...

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Tue, 2014-01-21 17:16

Thanks David, it now works perfectly.

Regards
Chris