Created
June 30, 2021 09:30
-
-
Save Daniil-Solovyev/bb873ee04bf0e14f07320997f4bf7b85 to your computer and use it in GitHub Desktop.
Удаление лишних пробелов
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$input = ' On my home world'; | |
/** | |
* @param string $input | |
* @param $separator | |
* @return string | |
*/ | |
function emptySpaces(string $input, $separator): string | |
{ | |
for ($i = 0; $i <= strlen($input); $i++) { | |
if ($input[$i] === $separator) { | |
while ($input[$i + 1] === $separator) { | |
$input = substr_replace($input, '', $i, 1);; | |
} | |
} | |
} | |
return $input; | |
} | |
echo emptySpaces($input, ' '); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment