Using preg_grep() : preg_grep « String « PHP






Using preg_grep()

 
<?
$text=<<<TEXT
"asdf.asdf,asdf!asdf
TEXT;

$words = preg_split('/[",.!\s]/', $text, -1, PREG_SPLIT_NO_EMPTY);

$double_letter_words = preg_grep('/([a-z])\\1/i',$words);

foreach ($double_letter_words as $word) {
    print "$word\n";
}
?>
  
  








Related examples in the same category

1.preg_grep
2.preg_grep() function searches all elements of input_array, returning all elements matching the regexp pattern.
3.Quickly finding lines that match a pattern