PHP string function - trim() instance usage

string trim ( string $str [, string $charlist = ” \t\n\r\0\x0B” ] )
This function returns the string str with leading and trailing whitespace characters removed. If the second parameter is not specified, trim() will strip these characters:
1.” ” (ASCII 32 (0x20)), the normal space character.
2. “\t” (ASCII 9 (0x09)), the tab character.
3. "\n" (ASCII 10 (0x0A)), a newline character.
4. “\r” (ASCII 13 (0x0D)), carriage return.
5. "\0" (ASCII 0 (0x00)), the null byte character.
6. "\x0B" (ASCII 11 (0x0B)), vertical tab character.

<?php
	$text = "\t\tThese are a few words :) ...  ";
	$binary = "\x09Example string\x0A";
	$hello = "Hello World";
	$str = "##\tUse the function trim to remove specific characters at both ends of the string####";

	$new_text = trim($text);
	$new_binary = trim($binary);
	$new_hello = trim($hello);
	$new_str = trim($str,"#");

	echo $new_text;		//These are a few words :) ...	
	echo $new_binary;	//Example string
	echo $hello;		//Hello World
	echo $new_str; //Use the function trim to remove specific characters at both ends of the string
?>

 

The above functions are also applicable to ltrim() and rtrim(), these two functions
1. ltrim(); delete the blank character (or other characters) at the beginning of the string
2. rtrim(); delete the blank character at the end of the string (or other characters)

 

At this point, basically the PHP string manipulation function has reached a paragraph. In the next article, we will start to summarize and sort out.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326771940&siteId=291194637