Need to remove the white space at the end of a string before recording the data. Use PHP’s rtrim().
rtrim is great for deleting that unwanted space at then end of strings. The perfect example for using this function is when receiving data from an online form and, at the end of a data field, some one leaves an extra white space. This white space means nothing and you want to delete it. rtrim() to the rescue.
<? $password = "123 "; $password = rtrim($password); // $password = "123" ?>
You can also trim down a string by matching words or letters and the end of a string.
// Example 1: Character-by-character comparison match. echo rtrim('This is a test test code', 'test code'); // returns 'This is a' // Example 2: matches the last whole word with half the letters echo rtrim('This is a test', 'est'); // returns 'This is a' ?>