You are here:  » Delete after name


Delete after name

Submitted by henk on Sun, 2013-08-11 12:04 in

Hi David,

I am trying to delete filter after a word filter after split doesn't work for me:

nike 123
nike 234
nike 4556

Delete everything after nike?

Thx
Henk

Submitted by support on Sun, 2013-08-11 12:43

Hi Henk,

There's a "Split Before" filter in this thread which it sounds like you may have already found, but in this example, that would also remove "Nike" of course; however the code can be easily modified to include the "split" string in the return value. Have a go with the following, based on the filter from the other thread but renamed "Delete After":

<?php
  
/*************************************************/
  /* deleteAfter                                   */
  /*************************************************/
  
$filter_names["deleteAfter"] = "Delete After";
  function 
filter_deleteAfterConfigure($filter_data)
  {
    print 
"Delete After Character or String:<br />";
    print 
"<input type='text' size='40' name='text' value='".widget_safe($filter_data["text"])."' />";
    
widget_errorGet("text");
  }
  function 
filter_deleteAfterValidate($filter_data)
  {
    if (!
$filter_data["text"])
    {
      
widget_errorSet("text","required field");
    }
  }
  function 
filter_deleteAfterExec($filter_data,$text)
  {
    
$p stripos($text,$filter_data["text"]);
    if (
$p!==FALSE)
    {
      
$text substr($text,0,$p+strlen($filter_data["text"]));
    }
    return 
$text;
  }
?>

I've made the above case-insensitive by using stripos, so "nike" or "Nike" will match, but if you wanted to keep case sensitivity then just change stripos to strpos.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Sun, 2013-08-11 13:14

Hi David,

Almost i think but it stripped it to 5 letters the complete import of all brands

Thx
Henk

Submitted by support on Sun, 2013-08-11 13:34

Hi Henk,

Made conditional to the search string being found, in the code above...

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Sun, 2013-08-11 13:40

Hi David,

Now it doesn't delete after a name or does anything?

Thx
Henk

Submitted by support on Sun, 2013-08-11 13:48

Hi Henk,

Should be OK now - added !== test to handle match string appearing at start...

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Sun, 2013-08-11 13:52

Hi David,

Now it works :)

Thx
Henk

Submitted by henk on Sun, 2013-08-11 14:28

Hi David,

Is it moaybe also possible to do it quicker like the mapped products idea only on brands?

Thx
Henk

Submitted by support on Mon, 2013-08-12 07:52

Hi Henk,

Sure - if you'd like to email me your latest includes/admin.php I'll modify Category Mapping so that it applies to brands also - quite a few users do this and there shouldn't be any cross-over due to the nature of brand names...

Cheers,
David.
--
PriceTapestry.com