RTrim
- (PHP 4, PHP 5, PHP 7)
- Rtrim-strip whitespace (or other characters) from the end of a string
- rtrim-Delete whitespace characters (or other characters) at the end of a string
Description
StringRTrim (String$str [,String$character _mask ] )//this function returns a string with whitespace (or all characters) stripped from the end of Str.//This function deletes the white space character (or other characters) at the end of STR and returns it. //without The second parameter, RTrim () would strip these characters://Do not use the second parameter, RTrim () deletes only the following characters:" " (ASCII + (0x20)), //an ordinary space. Plain white space characters. "\ t" (ASCII 9 (0x09)), //a tab. tab. "\ n" (ASCII Ten (0x0A)), //a New line feed. NewLine characters. "\ r" (ASCII - (0x0D)), //a carriage return. Carriage return. " /" (ASCII 0 (0x00)), //the null-byte.nul null byte character. "\x0b" (ASCII One (0x0B)), //a vertical tab. Vertical tab.
Parametersstr
- The input string.
- The input string.
Character_mask
- You can also specify the characters your want to strip, by means of the Character_mask parameter. Simply list all characters so want to be stripped. With.. You can specify a range of characters.
- By specifying Character_mask, you can specify a list of characters that you want to delete. Simply list all the characters you want to delete. Use.. Format, you can specify a range.
Return Values
- Returns the modified string.
- Returns the changed string.
Examples
<?php/*** Created by Phpstorm.* User:zhangrongxiang* DATE:2018/3/4* Time: PM 4:51 *///rtrim-Delete whitespace characters (or other characters) at the end of a string$hello="Hello World";//hello WorldEcho $hello.Php_eol;//hello WorldEcho RTrim( $hello ).Php_eol;//hello worlEcho RTrim( $hello, "D" ).Php_eol;//hello WorEcho RTrim( $hello, "DL" ).Php_eol;$text="\t\tThese is a few words:) ... ";//These is a few words:) ...Echo $text.Php_eol;//These is a few words:) ...Echo RTrim( $text ).Php_eol;//These is a few wordsEcho RTrim( $text, ":) ." ).Php_eol;$binary="\x09Example String\x0a";//Example stringEcho $binary.Php_eol;//Example stringEcho RTrim( $binary ).Php_eol;//Example stringEcho RTrim( $binary, "\x00..\x1f" ).Php_eol;/////////////////////////////////////////////////////////////////////////////////////functionStrrtrim( $message, $strip ){//Break Message apart by strip string $lines=Explode( $strip, $message ); Var_dump( $lines ); if ( Is_array( $lines ) ){//Pop off empty strings at the end Do{$last=Array_pop( $lines );} while ( Empty( $last )&&( Count( $lines ) ) );}Else{return "";}//re-assemble what remains return implode( $strip, Array_merge( $lines, Array( $last ) ) );}//hello,world,hiEchoStrrtrim( "Hello,world,hi", ' ' ).Php_eol;////////////////////////////////////////////////////////////////////////////////////$aFileContent=file( "rtrim.php" );foreach ( $aFileContent as $sKey=$sValue ){$aFileContent[ $sKey ]=RTrim( $sValue );}foreach ( $aFileContent as $sKey=$sValue ){if ( $sKey==Ten ){ Break;}Echo $sKey." ".$sValue.Php_eol;}//0 <?php//1/**//2 * Created by Phpstorm.//3 * User:zhangrongxiang//4 * DATE:2018/3/4//5 * Time: PM 4:51//6 * *//7//rtrim-Delete whitespace characters (or other characters) at the end of a string//8//9 $hello = "Hello World";//this is aEcho RTrim( ' This was a short short sentence ', ' short sentence ' ).Php_eol;//this is a short shortEcho RTrim( ' This was a short short sentence ', ' cents ' );////////////////////////////////////////////////////////////////////////////////////functionRead_more( $in, $len= - ){if ( strlen( $in )>$len ){return Preg_replace( '/[\s\.,][^\s\.,]*$/u ', '', substr( $in, 0, $len ) ).'...';}Else{return $in;}}//this is a short short Hello World,...EchoRead_more( "Hello World, PHP was the best language around the world" ).Php_eol;
See
- http://php.net/manual/zh/function.rtrim.php
All rights reserved
The RTrim () function of the PHP string is used