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. DRBD+Heartbeat实现自动切换

    1>HeartBeat介绍 Heartbeat 项目是 Linux-HA 工程的一个组成部分,它实现了一个高可用集群系统.心跳服务和集群通信是高可用集群的两个关键组件,在 Heartbeat 项 ...

  2. 咏南 DATASNAP LINUX中间件

    咏南 DATASNAP LINUX中间件,一套源码,同时支持WINDOWS和LINUX操作系统. 基于DELPHI 10.2 TOKYO开发 使用FIREDAC数据库引擎,支持MYSQL,MSSQL, ...

  3. 记一次很坑的python2与python3共存问题

    当添加PYTHONPATH环境变量时,无论输入pip2 -V还是pip3 -V都显示的是python2的环境变量,使用pip3 install 时也是安装在了python2的三方库(因为python2 ...

  4. SQL datediff()函数 时间差

    定义和用法 DATEDIFF() 函数返回两个日期之间的天数. 语法 DATEDIFF(datepart,startdate,enddate) startdate 和 enddate 参数是合法的日期 ...

  5. ASP.net 居中

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs& ...

  6. Java面试题(全)--视频系列

    此系列为面试笔试题的视频讲解,以下均为超链接,点击即可进入每个知识点的讲解. Java面试题01.面试的整体流程 Java面试题02.java的垮平台原理 Java面试题03.搭建一个java的开发环 ...

  7. Jzoj 初中2249 蒸发学水(并查集)

    题目描述 众所周知,TerryHu 是一位大佬,他平时最喜欢做的事就是蒸发学水. 机房的位置一共有n 行m 列,一开始每个位置都有一滴学水,TerryHu 决定在每一个时刻选择 一滴学水进行蒸发,直到 ...

  8. 一篇文章搞懂Linux安全!

    Linux是开放源代码的免费正版软件,同时也是因为较之微软的Windows NT网络操作系统而言,Linux系统具有更好的稳定性.效率性和安全性. 在Internet/Intranet的大量应用中,网 ...

  9. numpy 常用方法2

    Python之Numpy基础   一个栗子 >>> import numpy as np >>> a = np.arange(15).reshape(3, 5) & ...

  10. 解决pymysql.err.InternalError: (1366, "Incorrect string value: '\\xF0\\x9F\\x8C\\xB8' for column 'headline' at row 1")

    解决pymysql.err.InternalError: (1366, "Incorrect string value: '\\xF0\\x9F\\x8C\\xB8' for column ...