xxxxxxxxxx
$string = preg_replace('/\s+/', '', $string);
xxxxxxxxxx
<?php
// Example text containing whitespace
$text = " This is some text with whitespace. ";
// Using trim() function to remove leading and trailing whitespace
$trimmedText = trim($text);
// Output the trimmed text
echo $trimmedText;
?>
xxxxxxxxxx
//remove all white spaces from a string
$whatonearth=preg_replace('/\s/','',"what o n ear th");