Im looking for a regular expression to remove duplicates from a list that end with the letter s. Thanks in advance! The list BEFORE the duplicates are removed dog dogs Necklace Necklaces Bracelet Bracelets The list AFTER the duplicates are removed dog Necklace Bracelet
That works but only if its one word. How would i change your regexp to work with the example below? The list BEFORE the duplicates are removed dog bone dog bones 14k Gold Necklace 14k Gold Necklaces Gift Item Bracelet Gift Item Bracelets The list AFTER the duplicates are removed dog bone 14k Gold Necklace Gift Item Bracelet
Question, 1. what if you have only "dogs" in the list, not "dog" and "dogs". Do you want to replace "dogs" into "dog" too? 2. What if there is "glass" in your list. Do you want the last "s" to be removed too ("glas")
No, in this case "dogs" would stay the same "dogs" Im not asking how to remove 's' from the end of words
$items = file('file.txt'); $clean = array(); foreach($items as $item) { $item = strtolower($item); if(empty($clean[$item]) && empty($clean["{$item}s"]) && empty($clean["{$item}es"])) { $clean[$item] = true; } } $items = array_keys($clean); unset($clean); print_r($items); Code (markup):