$value=" kkkk.123 "; for ( $i=0; $i0; $i-- ) { if ( substr($value,$i,1) eq " " ) { $value = substr($value,0,$i); } }