Skip to content

Instantly share code, notes, and snippets.

@moff
Created February 28, 2017 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moff/c6f84071b7a6996879241dff0e90fa8c to your computer and use it in GitHub Desktop.
Save moff/c6f84071b7a6996879241dff0e90fa8c to your computer and use it in GitHub Desktop.
<?php
$arr = [
"hello world world",
"hello world world world",
"hello world world world world",
"hello hello world",
"hello hello hello hello world"
];
foreach ($arr as $str) {
echo preg_replace('/(\w{2,})(?=.*?\\1)\W*/', '',$str) . PHP_EOL;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment