Remove the Last Character From a PHP String

Removes the last character from a string, in the example below it is a comma. The last character can be a return character or tab or any other character.

$array = array_splice( $array, $n, 0, $item) );

Example:

String
$string = "This is a string with an unwanted character at the end of it..";

PHP:
$string = rtrim($string, '.');

Result:
"This is a string with an unwanted character at the end of it."


Example 2:

String - // in the string below notice the return which forces the quote to the next line.
$string = "This is a string with an unwanted character at the end of it.
";

PHP:
$string = rtrim($string, PHP_EOL);

Result:
"This is a string with an unwanted character at the end of it."