The character encoding used is important. In any encoding there is a symbol code, there is its semantics for the programmer and for the user.
A symbol for a programmer matters in the context of the algorithm and in the sense of what should be displayed to the user. The character code is what this difference stands for.
Syntax and meaning of trim function (PHP)
Usually a word, a phrase, a symbolic construction matters, but insignificant zeros or symbols do not always matter. Zeros in front of a number do not matter for the number and are used only for the purpose of aligning numerical information. Zeros before the first character of a character string and after the last also have no meaning, like spaces, tabs, line feeds and other "non-printable" characters.
The trim function in PHP has three options: trim, ltrim, and rtrim. The first removes insignificant characters from the beginning of the line and from its end. The second - only from the beginning. The third - only from the end.
The trim function in PHP has two parameters: the first is the line on which the action is performed, the second is the list of characters to be deleted. Special characters are indicated by codes, while regular characters are indicated as is. The range is allowed: "\ x11 .. \ x22".
It should be noted that trim in PHP without a second parameter removes insignificant (non-printable) special characters, including space. Indication of the list of characters to be deleted has nothing to do with spaces and special characters, if they are not specified.
The last example shows that the original string 'yy x20x18x yzx' produces a result with spaces, as well as with the character 'x' inside the string.
Using the trim function to process strings
With the modern performance of computer equipment, all string functions are equal in speed, but in each case, when processing significantly large amounts of information, it makes sense to compare various algorithms that use different string functions, and then choose the best option.
Typically, a programmer uses strpos and substr or str_replace to perform string conversion and get the desired result. Why not use trim PHP? This function by its syntactic purpose does not limit the programmer in use.
The comparison operator if or the switch construct is used to select the desired direction in the algorithm, but the condition they have can be dynamically changed by trim. PHP does not restrict the developer neither in the first parameter, nor in the second, does not prohibit the result of the function from supplementing at the place of receipt.
A good example is the use of regular arrays to convert decimal digits to hexadecimal. If you simply add all hexadecimal digits to the empty array in ascending order, you get a direct correspondence of decimal indices to their hexadecimal values.
When processing characters using the trim function, PHP also does not impose any restrictions. Having correctly compiled the second parameter, you can step by step change the content of the first parameter, use it as a condition for choosing the direction of the algorithm.
Stack, recursion and PHP trim
Stack processing is promising. The chances that she will ever leave the spectrum of the most sought-after ideas in the development of algorithms are very few. The level of recursiveness of a function, that is, its ability to call itself without any restrictions, is a criterion for the quality of the function.
Implementing trim in PHP is a good help to implement modern ideas. This function works strictly sequentially along the edges of the source line; it allows symbol-by-symbol processing and can be executed as a higher-level process control algorithm.