Skip to content

Instantly share code, notes, and snippets.

@Sirpyerre
Created January 28, 2022 21:28
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 Sirpyerre/fae8ad7cd00d162efd1aa2508656b1cd to your computer and use it in GitHub Desktop.
Save Sirpyerre/fae8ad7cd00d162efd1aa2508656b1cd to your computer and use it in GitHub Desktop.
<?php
// "internacionalization oso entertainment internacionalization oso entertainment ahho atto a2o a2o" => "i18n oso e11t internacionalization oso entertainment"
// "apa water a aa"
echo summarize("internacionalization oso entertainment");
function summarize(string $input)
{
$words = explode(" ", $input);
$sizeTmp = count($words);
$resume = "";
$output = [];
$duplicates = [];
for ($i=0;$i<$sizeTmp; $i++){
$duplicates[] = $words[$i];
$duplicates[$words[$i]] = 1;
$duplicates["internacionalization"] = 1;
if(isset($duplicates["internacionalization"])) {
$duplicates["internacionalization"]++;
}
$str = $words[$i];
$size = strlen($str);
if ($size > 3) {
$resume = $str[0] . ($size-2) . $str[$size-1];
$output[$i] = $resume;
} else {
$output[$i] = $str;
}
}
return implode(" ",$output);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment