You are here:  » Explode on - (hyphen/dash)


Explode on - (hyphen/dash)

Submitted by ivohofland on Tue, 2015-01-27 12:43 in

Hi David,

In some feeds I have the following category path: Heren - Hardlopen - Hardloopjassen. I would like to use the explode filter to select one of those words for the category. But this doens't seem to work with the - sign. I used the same method as I've been using for the > sign, but adding the - result in errors. Can you help me out with this?

Kind regards,

Ivo

Submitted by support on Tue, 2015-01-27 14:49

Hello Ivo,

The Explode filter could actually result in an unset() error if the field it was applied had less values (after being split) that then return index. I will correct this in the distribution, but to apply the change if you edit includes/filter.php and look for the following code at line 291:

  return $parts[$index];

...and REPLACE with;

  return (isset($parts[$index])?$parts[$index]:"");

Regarding the split itself, there are 2 hyphen characters defined in the extended UTF-8 character set that appear visually identical to the ASCII hyphen / minus character, so if the split has not worked as expected try using one of the following, using COPY and PASTE from the hyphen characters below directly into the Explode Character or String box on the configuration page for the filter:

UTF-8 Hyphen:

UTF-8 Non-breaking Hyphen:

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by ivohofland on Tue, 2015-01-27 15:30

Hi David,

I've edited the code and I've tried both hyphens but no result. Then I tried to add the hyphen in includes/admin.php:

      $importRecord["category"] = tapestry_normalise($importRecord["category"],">|\/-");

That resulted in the following errors after importing:

Warning: preg_replace(): Compilation failed: range out of order in character class at offset 19 in /home/transpor/public_html/pt/includes/tapestry.php on line 27

No products where imported. Then i've tried to escape the hyphen:

      $importRecord["category"] = tapestry_normalise($importRecord["category"],">|\/\-");

But with this the explode still didn't find place.

Submitted by support on Tue, 2015-01-27 16:16

Hello Ivo,

Sorry about that - please could you email me a link to the installation and filename of the feed if convenient, or if the feed is relatively small if you could .zip and attach to an email I'll study the category field to see exactly how it is encoded and check it out further for you...

Cheers,
David.
--
PriceTapestry.com