Php Remove Spaces
If you want to remove all whitespaces including tabs newlines etc.
Php remove spaces. Without the second parameter trim will strip these characters. Ascii 32 0x20 an ordinary space. If you want to remove whitespace only from the end of a string you should use the rtrim function in php.
Ltrim removes whitespace or other predefined characters from the left side of a string rtrim removes whitespace or other predefined characters from the right side of a string. You can use the php trim function to remove whitespace including non breaking spaces newlines and tabs from the beginning and end of the string. If you want to remove whitespace from both ends of a string you should use the trim function instead of using both ltrim and rtrim.
The above example will however only remove spaces. In order to do this task we have the following methods in php. Use the php trim function.
Php trim remove whitespace from string php trim function is used for removing the white space or other characters from starting and end of a string. The output should be my name is john smith my favourite subject is php. It will not remove whitespace occurs in the middle of the string.
This function returns a string with whitespace stripped from the beginning and end of str. An ordinary space. T ascii 9 0x09 a tab.
Its used for formatting data properly. The str replace method is used to replace all the occurrences of the search string by replacing string in the given string str. You can use the preg replace function which perform a regular expression search and replace as demonstrated in the following example.