$ Str1 = "tt Happy Chinese Valentine's Day! Nr "; // define a character variable, including" space "," t ", horizontal tab," n ", Line Break // The trim () function is called to remove spaces. The trim () function is used to remove the "" space "," t "Horizontal tab" n "linefeed, and" r "carriage return. // "\ 0" string Terminator and "xOB" vertical tab. If you want to use this function to filter out special characters, you can specify the second parameter. Echo trim ($ str1 )." "; // Remove the tt characters in the $ str1 variable. Echo trim ($ str1, "tt ")." "; // Define the variable $ str2, which includes "." And space. $ Str2 = "... Happy Valentine's Day !... China ..."; // Call the trim () function to remove spaces in the $ str2 variable Echo trim ($ str2 )." "; // The ltrim () function is used to remove spaces or specified strings on the left of the string. The default character is the same as trim. Because the second parameter is specified here, // Therefore, only the "." on the left of the $ str2 variable is removed "." Echo ltrim ($ str2 ,".")." "; // The ltrim () function is used to remove spaces on the right side of a string or specify a string. The default character is the same as trim. Because the second parameter is specified here, // Therefore, only the "." on the left of the $ str2 variable is removed "." Echo rtrim ($ str2 ,".")." "; ?> Echo substr ("today is father day! ", 0 )." "; Echo substr ("today is father day! ", 6, 2 )." "; // Here, only the 6th characters in the string are captured and only 2 characters are captured. Echo substr ("today is father day! ",-5, 5 )." "; // It starts from the last 5th characters of the string and intercepts 5 characters. Echo substr ("today is father day! ", 0,-5 )." "; // Here, only the first character in the string is intercepted and the last 5th characters in the string are intercepted. Echo substr ("today is father day! ",-5,-1 )." "; // Here, the string starts from the last 5th characters, and the first to the last character is truncated. ?> |