What is the difference between trim() and rtrim() functions in PHP?
The trim() function in PHP removes whitespace (or other characters) from both the beginning and end of a string. On the other hand, the rtrim() function only removes whitespace (or other characters) from the end of a string. If you want to remove leading and trailing whitespace, use the trim() function. If you only want to remove trailing whitespace, use the rtrim() function.
// Example of using trim() function
$string = " Hello World ";
$trimmedString = trim($string);
echo $trimmedString; // Output: "Hello World"
// Example of using rtrim() function
$string = " Hello World ";
$rtrimmedString = rtrim($string);
echo $rtrimmedString; // Output: " Hello World"