Hello, I have a problem where in some products I have some special characters within the text, and I tried changing the encoding and the utf8 encode/decode and none of this helped...
I actually have those same characters in the feeds themselves, here is an example directly from the feed:
The “Rattler� produces a sound very similar to “sizzle� cymbals, but louder and more sustained.
So I tried to preg_replace('/[^A-Za-z0-9\. ]/e','',$mainProduct["description"]); in html/product.php and that solved it, but preg_replace is a pretty slow function (from what I know) so I wanted to create a filter that I could apply to the problematic feeds, that will do the function on the import instead. (remove all non alphanumeric characters excluding the "." and a single space)
So I searched the forum for a tutorial to create a new filter, and found nothing :( - Are there any guides I could follow to create such a filter??
Thanks
Pasha
That worked like a charm! - Thank you so so much!
Hi Pasha,
I've just made a copy of the search and replace filter using your code above - as a "preg Replace" filter. To use this, simply paste the code below into includes/filter.php:
/*************************************************/
/* pregReplace */
/*************************************************/
$filter_names["pregReplace"] = "preg Replace";
function filter_pregReplaceConfigure($filter_data)
{
print "preg Expression:<br />";
print "<input type='text' name='search' value='".widget_safe($filter_data["search"])."' />";
widget_errorGet("search");
print "<br /><br />";
print "Replace:<br />";
print "<input type='text' name='replace' value='".widget_safe($filter_data["replace"])."' />";
widget_errorGet("replace");
}
function filter_pregReplaceValidate($filter_data)
{
if (!$filter_data["search"])
{
widget_errorSet("search","required field");
}
}
function filter_pregReplaceExec($filter_data,$text)
{
return preg_replace($filter_data["search"],$filter_data["replace"],$text);
}
So to use this, simply enter your expression as the "preg Expression" field:
/[^A-Za-z0-9\. ]/e
...and leave the "Replace" field blank...
Hope this helps!
Cheers,
David.