Php deletes spaces on the left and right sides. php deletes spaces on the left side. Php deletes spaces on the left and right sides. This document describes how to delete spaces on the left and right sides of php. Share it with you for your reference. The specific method is as follows: php deletes spaces on the left side and on the right side. php deletes spaces on the left side.
This example describes how to delete spaces on the left and right sides of php. Share it with you for your reference. The specific method is as follows:
Deleting functions in php is much more specific than js. in addition to the trim () function, there are also ltrim () and rtrim () functions. they need to delete spaces between front and back, respectively, in addition to the three functions, you can also use regular expressions to delete them.
Ltrim () function: ltrim ($ str, $ charlist)
$ Str indicates the processed string. $ charlist is a special character to be deleted. if it is null, spaces on the left are removed. the code is as follows:
The code is as follows:
<? Php
$ T = "... I'm Jacky ...";
Echo "a". $ t ."
";
$ Left = ltrim ($ t );
Echo "a". $ left ."
";
$ Lleft = ltrim ($ left ,".");
Echo $ lleft;
?>
Rtrim () function: rtrim ($ str, $ charlist)
$ Str indicates the processed string. $ charlist is a special character to be deleted. if it is null, spaces on the right are removed. the code is as follows:
The code is as follows:
<? Php
$ A = "htm ";
Echo $ a. "l "."
";
Echo rtrim ($ a). "l ";
?>
Trim () function,First, remove the leading and trailing spaces. the code is as follows:
The code is as follows:
$ Str = "This line containstliberal rn use of whitespace. nn ";
// First remove the leading and trailing spaces
$ Str = trim ($ str );
// Remove the two or more spaces
$ Str = preg_replace ('/s (? = S)/', '', $ str );
// Replace a non-space with a space.
$ Str = preg_replace ('/[nrt]/', '', $ str );
In the preceding example, we can remove all unnecessary spaces. First, we use TRim () to remove leading and trailing spaces, and then use preg_replace () to remove repeated spaces.
Replace with regular expressionsPhp removes spaces at the beginning and end of the string (including the full angle). The code is as follows:
The code is as follows:
<? Php
$ Str = "www.www.jb51.net ";
$ Str = mb_ereg_replace ('^ (|) +', '', $ str );
$ Str = mb_ereg_replace ('(|) + $', '', $ str );
Echo mb_ereg_replace (''," n ", $ str );
?>
I hope this article will help you with PHP programming.
Examples in this article describes how to delete spaces on the left and right sides of php. Share it with you for your reference. The specific method is as follows :...