rtrim

  • (PHP 4, PHP 5, PHP 7)
  • rtrim — Strip whitespace (or other characters) from the end of a string
  • rtrim — 删除字符串末端的空白字符(或者其他字符)

Description

string rtrim ( string $str [, string $character_mask ] )
//This function returns a string with whitespace (or other characters) stripped from the end of str.
//该函数删除 str 末端的空白字符(或者其他字符)并返回。 //Without the second parameter, rtrim() will strip these characters:
//不使用第二个参数,rtrim() 仅删除以下字符: " " (ASCII 32 (0x20)), //an ordinary space.普通空白符。
"\t" (ASCII 9 (0x09)), //a tab.制表符。
"\n" (ASCII 10 (0x0A)), //a new line (line feed).换行符。
"\r" (ASCII 13 (0x0D)), //a carriage return.回车符。
"\0" (ASCII 0 (0x00)), //the NULL-byte.NUL 空字节符。
"\x0B" (ASCII 11 (0x0B)), //a vertical tab.垂直制表符。

Parameters

str

  • The input string.
  • 输入字符串。

character_mask

  • You can also specify the characters you want to strip, by means of the character_mask parameter. Simply list all characters that you want to be stripped. With .. you can specify a range of characters.
  • 通过指定 character_mask,可以指定想要删除的字符列表。简单地列出你想要删除的全部字符。使用 .. 格式,可以指定一个范围。

Return Values

  • Returns the modified string.
  • 返回改变后的字符串。

Examples

<?php
/**
* Created by PhpStorm.
* User: zhangrongxiang
* Date: 2018/3/4
* Time: 下午4:51
*/
//rtrim — 删除字符串末端的空白字符(或者其他字符) $hello = "Hello World";
//Hello World
echo $hello . PHP_EOL;
//Hello World
echo rtrim( $hello ) . PHP_EOL;
//Hello Worl
echo rtrim( $hello, "d" ) . PHP_EOL;
//Hello Wor
echo rtrim( $hello, "dl" ) . PHP_EOL; $text = "\t\tThese are a few words :) ... ";
// These are a few words :) ...
echo $text . PHP_EOL;
// These are a few words :) ...
echo rtrim( $text ) . PHP_EOL;
// These are a few words
echo rtrim( $text, ":) ." ) . PHP_EOL; $binary = "\x09Example string\x0A";
// Example string
echo $binary . PHP_EOL;
// Example string
echo rtrim( $binary ) . PHP_EOL;
// Example string
echo rtrim( $binary, "\x00..\x1F" ) . PHP_EOL; /////////////////////////////////////////////////////////////////////////////////////
function strrtrim( $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,hi
echo strrtrim( "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 == 10 ) {
break;
}
echo $sKey . " " . $sValue . PHP_EOL;
}
//0 <?php
//1 /**
//2 * Created by PhpStorm.
//3 * User: zhangrongxiang
//4 * Date: 2018/3/4
//5 * Time: 下午4:51
//6 */
//7 //rtrim — 删除字符串末端的空白字符(或者其他字符)
//8
//9 $hello = "Hello World"; //This is a
echo rtrim( 'This is a short short sentence', 'short sentence' ) . PHP_EOL;
//This is a short short
echo rtrim( 'This is a short short sentence', 'cents' ); ////////////////////////////////////////////////////////////////////////////////////
function read_more( $in, $len = 16 ) {
if ( strlen( $in ) > $len ) {
return preg_replace( '/[\s\.,][^\s\.,]*$/u', '', substr( $in, 0, $len ) ) . '...';
} else {
return $in;
}
} //This is a short short hello world,...
echo read_more( "hello world, php is the best language around the world" ) . PHP_EOL;

See

All rights reserved

PHP之string之rtrim()函数使用的更多相关文章

  1. PHP函数详细剖析之rtrim函数 By ACReaper

    string rtrim ( string $str [, string $charlist ] ) 这个函数很好理解.r表示右边.trim表示修剪.即右边修剪.默认修剪字符str右边的字符.默认修剪 ...

  2. php rtrim()函数 语法

    php rtrim()函数 语法 rtrim()函数怎么用? php rtrim()函数用于删除字符串右边的空格或其他预定义字符,语法是rtrim(string,charlist),返回经过charl ...

  3. OC与c混编实现Java的String的hashcode()函数

    首先,我不愿意大家需要用到这篇文章里的代码,因为基本上你就是被坑了. 起因:我被Java后台人员坑了一把,他们要对请求的参数增加一个额外的字段,字段的用途是来校验其余的参数是否再传递过程中被篡改或因为 ...

  4. string类find函数返回值判定

     string类find函数返回值判定 代码示例 #include<iostream> #include<cstring> using namespace std; int m ...

  5. C string.h 常用函数

    参考:http://womendu.iteye.com/blog/1218155 http://blog.csdn.net/zccst/article/details/4294565 还有一些,忘记了 ...

  6. c++中string的常用函数说明

    string可以说是是字符数组的升级版,使用更加啊方便,不容易出错.本文对string的常用函数进行简单介绍,做到会用即可. string中的常用函数分为四类,即赋值,添加,比较和删除. 一.赋值 1 ...

  7. C++ string类及其函数的讲解

    文章来源于:http://www.cnblogs.com/hailexuexi/archive/2012/02/01/2334183.html C++中string是标准库中一种容器,相当于保存元素类 ...

  8. rtrim() 函数 从字符串的末端开始删除空白字符!

    例子 在本例中,我们将使用 rtrim() 函数从字符串右端删除字符: <?php $str = "Hello World!\n\n"; echo $str; echo rt ...

  9. PHP之string之explode()函数使用

    explode (PHP 4, PHP 5, PHP 7) explode - Split a string by string explode - 使用一个字符串分割另一个字符串 Descripti ...

随机推荐

  1. 更改mysql默认字符集 (转载)

    1. service mysqld stop,停用mysql. 2. cp /etc/my.cnf /etc/my.cnf.bak,修改前做备份,这是个好习惯. 修改my.cnfvi /etc/my. ...

  2. 在Github注册账户

    https://github.com/JasonHaoz

  3. Python学习-10.Python函数定义(二)

    在Python中定义函数的时候,可以使用参数默认值的方式定义函数 例子: def welcome(who,state='is',action='talking'): print(who,state,a ...

  4. Visual Studio 2017(VS2017) 企业版 Enterprise 注册码

    Visual Studio 2017(VS2017) 企业版 Enterprise 注册码:NJVYC-BMHX2-G77MM-4XJMR-6Q8QF 终于等到你,最强 IDE Visual Stud ...

  5. Azure静态公网ip自助反解

    Linux下安装az工具,并登陆 az login 执行 az network public-ip update --resource-group ip所在资源组名称 --name ip对应资源名称 ...

  6. JS——EasyuiCombobox三级联动

    有许多刚接触Easyui中Combobox控件的朋友可能都会遇到的问题:如何将Combobox做成三级联动? 现分享一个三级联动的案例给大家参考参考,经测试能通过.注意Combobox绑定的数据是Js ...

  7. IdHTTPServer使用注意问题

    如果在同一电脑上运行多个IdHTTPServer实例,IdHTTPServer使用时候,一定要注意“DefaultPort”属性,其实真正绑定端口是这个属性决定的,所以希望IdHTTPServer绑定 ...

  8. 虚拟机搭建ftp环境

    引用http://www.cnblogs.com/xiangxiaodong/archive/2013/12/23/3487028.html,学习. 本人是在windows8系统下,Oracle VM ...

  9. jdk完全卸载(亲测jdk1.7.0_80在win7)

    1.从控制面板里删除java程序 2.删除注册表:HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\ 3.删除C:\Windows\System32 和 C:\Windows\ ...

  10. C#-WebForm-★★★LinQ-数据的条件组合查询并进行分页展示(未加各种限定)★★★

    前台代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.as ...