
PHP TRIM LAST 4 CHARACTERS CODE
When we try the same code by removing the trim function we can see that an extra tab will get printed at the end of the string as we have appended it in a $str_new parameter. Simultaneously trim function is used which removes this tab character from the end of the string.

First, we are assigning the required string to a parameter called str1, and then using another parameter $str_new to append a tab at the end of the $str1. In the above example, we are using the trim function to remove tab (“\t”) character by explicitly specifying the character in the second parameter of the trim function as seen. After using the trim function as seen in the output it trims all the \n present in the input string and displays the string. Here $str is the variable to which the required string or a sentence is to be declared. The above example displays a basic program for the usability of trim() function. The same thing can be seen in the output. In the string assigned we are displaying newlines as part of the sentence for testing purposes. In the above example, we are showcasing to see the output without the use of the trim() function. Given below are the examples of trim() in PHP: Example #1 – To remove the newline character. rtrim(): This is used to trim characters from the end of the input string.ltrim(): This is used to trim characters from the beginning of the input string.trim(): This is a normal one and can be used to trim from both the beginning and end of a string.There are 3 different types of trim() functions that can be used for the below-mentioned purposes: Return values: Outputs a trimmed string.With this, we can also specify a wide range of characters. All the characters mentioned inside the braces will be trimmed. character_mask: This is an optional field that can also be specified using this parameter.str: This is the input string that will be trimmed of whitespaces.“\x0B” (ASCII 11 (0x0B)) which represents a vertical tab.“\0” (ASCII 0 (0x00)) which is called the NULL byte.“\r” (ASCII 13 (0x0D)) which is a carriage return character.“\n” (ASCII 10 (0x0A)) which represents a new line character.

