Skip to content

Instantly share code, notes, and snippets.

@JamshidbekAkhlidinov
Last active May 22, 2024 14:41
Show Gist options
  • Save JamshidbekAkhlidinov/cd5f4fac94ec1e58fed82df4e12ca411 to your computer and use it in GitHub Desktop.
Save JamshidbekAkhlidinov/cd5f4fac94ec1e58fed82df4e12ca411 to your computer and use it in GitHub Desktop.
Used to make several spaces into one.
<?php
function clearBetweenOnText($text)
{
$array = explode(" ", $text);
$ClearArray = array_filter($array, function ($value) {
return !empty(trim($value));
});
$arrayValues = array_values($ClearArray);
return implode(" ", $arrayValues);
}
$string = 'Some valid and dsad text!';
echo clearBetweenOnText($string). "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment