Entry
Is there a function that ignores white space in a string?
Dec 13th, 2002 01:20
Philip Olson, Tam bouma, Narendra Jain, obi-wan kenobi,
Basically, you can replace the spaces with nothing so let's do that
using the str_replace() function.
<?php
$string = " New York, New York ";
$string = str_replace(' ', '', $string);
// NewYork,NewYork
print $string;
?>
See also:
http://www.php.net/str_replace
If you simply wanted to remove the trailing or leading whitespace then
use trim():
<?php
$string = " New York, New York ";
$string = trim($string);
// New York, New York
print $string;
?>
It's hard to demonstrate but trust us, the leading and trailing
whitespace is gone now :)
See also:
http://www.php.net/trim