Removing spaces from the start and end of a string
Posted: Thu Jun 10, 2004 3:56 am
I'm having a few problems trying to remove spaces from the beginning and end of a sting (if either or both first and last character is a space). Any spaces in the middle of the string are ok, so str_replace isn't the solution.
What I have so far is:
This of course gives parse errors at $explode[length]. Can anyone advise me how I can check if the last value in the exploded array is a space?
What I have so far is:
Code: Select all
$length = strlen($string);
$explode = explode("", $string);
if ($explodeї0] == " "){
array_shift($explode);
}
if ($explodeї$length]) == " "){
array_pop($explode);
}
$string = implode("", $explode);