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
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
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
Thanks David, it now works perfectly.
Regards
Chris
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