You are here:  » Limit product name


Limit product name

Submitted by jonny5 on Sat, 2010-11-27 13:03 in

Hi again david , is there something i can add to a filter so the product name is only so many characters or words long , ie so the rest is dropped

cheers

Submitted by support on Sat, 2010-11-27 13:14

Hi Jonny,

Here is a new filter that will truncate a string on the next SPACE character after the specified limit (so that it doesn't break whole words). Add the following code to the end of your includes/filter.php file, just before the closing PHP tag:

  /*************************************************/
  /* Truncate */
  /*************************************************/
  $filter_names["truncate"] = "Truncate";
  function filter_truncateConfigure($filter_data)
  {
    print "Character Limit:<br />";
    print "<input type='count' size='40' name='count' value='".widget_safe($filter_data["count"])."' />";
    widget_errorGet("count");
  }
  function filter_truncateValidate($filter_data)
  {
    if (!$filter_data["count"])
    {
      widget_errorSet("count","required field");
    }
  }
  function filter_truncateExec($filter_data,$text)
  {
    if (strlen($text) > $filter_data["count"])
    {
      $breakOffset = strpos($text," ",$filter_data["count"]);
      if ($breakOffset !== false)
      {
        $text = substr($text,0,$breakOffset).$append;
      }
    }
    return $text;
  }

Cheers,
David.
--
PriceTapestry.com

Submitted by affiliben on Tue, 2013-04-16 15:46

Hi David
Sorry to bother you again.
I have just found this filter and it is exactly what I need but on some feed fields it is throwing up the following error

Warning: strpos() [function.strpos]: Offset not contained in string in (Path to) /filter.php on line 436
Warning: Cannot modify header information - headers already sent by (output started at (Path to) /filter.php:436) in
(Path to) /admin/feeds_import.php on line 31

The truncate filter is at end of my filters and line 436 is
$breakOffset = strpos($text," ",$filter_data["count"]);
Do you have any idea why that might happen?
Thanks
Ben

Submitted by support on Tue, 2013-04-16 15:52

Hi Ben,

Corrected above - this line:

    if (strlen($text) > $length)

...should actually be:

    if (strlen($text) > $filter_data["count"])

Cheers,
David.
--
PriceTapestry.com

Submitted by affiliben on Tue, 2013-04-16 19:05

Works a treat
Excellent Help as Always
Thanks
Ben