Remove White Spaces from String: Write a PHP function to remove all white spaces from a given string.

function removeWhiteSpace($str) {
    return preg_replace('/\s+/', '', $str);
}

// Example usage:
$string = "  Hello   World  ";
echo "String without white spaces: " . removeWhiteSpace($string);

Related Posts

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Artificial Intelligence