The simplest way to clear a space in PHP is to use the trim () function, but this function is often not up to the result we want, especially if the string has characters like \\r\\n that cannot be made, and here's a perfect solution to this problem.
The code is as follows
Copy Code
$STR = "This line containstliberal RN use of whitespace.nn";Remove the opening and closing b
The simplest way to clear spaces in php is to use the trim () function, but this function often fails to reach the desired result. in particular, it cannot be created when the string has characters such as rn, lower
The simplest way to clear spaces in php is to use the trim () function, but this function often fails to achieve what we want, in particular, strings
$text = "\t\tthese is a few words:) ... ";
Var_dump ($text);
Echo '----------------------------------';
Echo '
';$trimmed = Trim ($text);Var_dump ($trimmed);$trimmed = Trim ($text, "\ t:)");Var_dump ($trimmed);Output:String ' These is a few words:) ... ' (length=28)String ' These is a few words:) ... ' (length=28)$trimmed = T
JavaScript -- add the trim, ltrim, and rtrim methods to the String object in JavascriptUsing the prototype attribute of each Object in Javascript, we can add our own method to the built-in objects in Javascript.
And attributes. Here we will use this attribute to add three methods for the String object: Trim, LTrim, RT
Using jquery to remove the front and back spaces of a string is simple, use $.trim (Stringtext);//stringtext is a string to remove a space
$.trim (str)
Back: string;
Description: Remove the string and end space.
Example:
Firs
Example of using string trim () in JS, jstrim
Example 1:
Example 2:
// Clear the space String on both sides. prototype. trim = function () {return this. replace (/(^ \ s *) | (\ s * $)/g, '') ;}; // Merge multiple spaces into a blank String. prototype. resetBlank = function
If your project is using the JQuery framework, you will of course Choose: Jquery.trim (String) to remove the null characters from the end of the string. If you don't use jquery as a simple implementation. I have previously sent a small snippet of code: JavaScript to remove the string around the space-trim (), this writ
String Trim (String $str [, String $charlist = "\t\n\r\0\x0b"])This function returns the result of the string str after removing the trailing whitespace characters. If you do not specify a second parameter, trim () will remove the
The shell implements the trim function effect to remove spaces on both sides of the string, and the following three commands are equivalent, all of which can be implementedSed ' s/^\s*//' totrim.txt |sed ' s/\s*$//' >trimed.txtSed ' s/^\s*//;s/\s*$//' totrim.txt>trimed.txtSed-e ' s/^\s*//'-e ' s/\s*$//' totrim.txt>trimed.txtThe main thing is to use regular expressions, ^\s* represents 0 or more spaces in fr
(1) Flat arrayThis is a well-known internet company today's front-end written questions: multidimensional array dimension variable, such as [2,4,1,[2,3,4,[1,2],5,3],3,8] beat flat for [2,4,1,2,3,4,1,2,5,3,3,8]. The number of dimensions is variable and should be recursive:Answer:function flatten(arr){var arrLength=arr.length;fori=0;ii++){ if(arr[i].constructor==Array){ arr.splice(i,1,flatten(arr[i])); }}return arr;}(2) Extract the parameters from the URL into an objectThis is also an
This article summarizes PHP's commonly used string manipulation functions. Share to everyone for your reference, as follows:
/* Common string output function * * the echo () output String * print () outputs one or more strings * die () outputs a message and exits the current script * printf () output formatted string
In the following example, we use this attribute to add three methods to the String object: Trim, LTrim, and RTrim (same as the function of the same name in VbScript)
Copy codeThe Code is as follows: String. prototype. Trim = function ()
{
Return this. replace (/(^ \ s *) | (\ s * $)/g ,"");
}
In the following example, we use this attribute to add three methods to the String object: Trim, LTrim, and RTrim (same as the function of the same name in VbScript)Copy codeThe Code is as follows: String. prototype. Trim = function (){Return this. replace (/(^ \ s *) | (\ s * $)/g ,"");}
/*commonly used string output function * * the echo () output String * print () outputs one or more strings * die () outputs a message and exits the current script * printf () output formatted string * sprintf () writes the formatted string to a variable **///Ucfirst//Converts the first letter in a
This method removes whitespace characters from both sidesPrinciple:See the source code implementation PublicString Trim () {intLen =value.length; intSt =0; Char[] val = value;/*avoid GetField opcode*/ while(St ' ') ) {St++; } while(St 1] ' ') ) {len--; } return(St >0) || (Len This; }View CodeAccording to the source, the string is split into a character array, and then the ASCII code
This article mainly introduces common string operation functions in PHP, and summarizes and analyzes common PHP skills for string operation in combination with examples, which has some reference value, you can refer to the examples in this article to summarize common PHP string operation functions. We will share this with you for your reference. The details are a
This article mainly introduces common string operation functions in PHP, and summarizes and analyzes common PHP skills for string operation in combination with examples, which has some reference value, you can refer to the examples in this article to summarize common PHP string operation functions. We will share this with you for your reference. The details are a
Using the prototype property of each object in JavaScript, we can add our own methods and properties to the built-in objects in JavaScript.
Here's how we use this property to add three methods to a String object: Trim,ltrim,rtrim (acting like a function with the same name in VBScript)
String.prototype.Trim = function ()
{
Return This.replace (/(^\s*) | ( \s*$)/g, "");
}
String.prototype.LTrim = function
This article is mainly to introduce the JavaScript extension method string trim () The use of the guide, very simple and practical, the need for small partners can refer to.
Example one:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17-18
Example two:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30-31 33 34 35 36 37 38 39 40 41 42 43
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.