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. asp.net mvc部分视图的action中获取父级视图信息

    RouteData.DataTokens["ParentActionViewContext"]中包含了父级视图的相关信息,如路由等 public ActionResult Chil ...

  2. C# Session操作

    Session.Abandon();//清除全部Session//清除某个SessionSession["UserName"] = null;Session.Remove(&quo ...

  3. DevExpress GridControl使用教程:之 添加 checkbox 复选框

    添加一列,FieldName为"FLAG",将ColumnEdit设置为复选框样式. gridview1   =>optionsbehavior =>  editabl ...

  4. WCF实现进程间管道通信Demo

    一.代码结构: 二.数据实体类: using System; using System.Collections.Generic; using System.Linq; using System.Run ...

  5. 如何实现一个IOS网络监控组件

    此文由作者朱志强授权网易云社区发布. Mobile Application Monitor IOS组件设计技术分享 背景 应用程序性能管理Application Performance Managem ...

  6. iOS 模拟器网络设置

    在 iOS Simulator 下,点上面菜单栏最左面的苹果标志,第三项 网络设置,然后先最后面一项,网络设置. 然后在网络设置界面下可以开启或关闭网络.

  7. unix网络编程卷2:进程间通信

    管道没有名字,只能有亲缘关系使用. FIFO也叫有名管道,有名所以没有了这个限制. 管道提供一个单向数据流,创建函数返回两个文件描述符.一个用来读,一个用来写. 宏S_ISFIFO可用于确定一个描述符 ...

  8. “全栈2019”Java第八十七章:类中嵌套接口的应用场景(拔高题)

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  9. Vue 框架 笔记

    1.兼容 2.性能优化   vuejs ******作者:尤雨溪 *** *******MVVM框架: M:model层 数据层 数据的增删改查 V:view视图层 类似于html的模板 vm:vie ...

  10. luoguP5074 Eat the Trees

    https://www.luogu.org/problemnew/show/P5074 插头 $ dp $ 入门题 如果你还不会插头 $ dp $ 请右转 洛谷插头dp题解 虽然是入门题但还是逃不过分 ...