<?php
function space($sentence) {

$sentence= trim($sentence); //trim function-Breaks a sentence after spaces.

//str_contains-Checks if there is a blank in this sentence in this situation.
while (str_contains($sentence, '  ')) {

// str_replace-Replaces the first element with the second element in this sentence.
$sentence= str_replace('  ', ' ',$sentence);
}
return $sentence;
}
$sentence "  hi     i    am   gvanca";
echo space($sentence);
by Gvanca Gharibashvili
2 years ago
PHP
Object Oriented PHP Tutorial
0
Pro tip: use ```triple backticks around text``` to write in code fences