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. Oracle ERP View - fnd_global.apps_initialize

    在ORACLE APPLICATION FORM中已存储了数据,在客户端TOAD中查找其TABLE找到相关数据行,但当查找其VIEW时就无法找到数据. 原因ORACLE的权责及OU安全机制屏蔽问题. ...

  2. 咏南中间件新增SQL日志

    为了方便开发时跟踪调试SQL语句的执行情况,咏南中间件新增SQL日志,所有执行过的SQL都会写入SQL日志文件中. SQLDEBUG设为1,启用:设为0,停止写SQL日志.

  3. 国内顶尖的sql dba 团队招人。

    国内顶尖的sql dba 团队招人. 4年DBA 经验 我们希望你掌握 1.熟练关系型数据库原理.熟练一门语言(C# .Java.Python.powershell ) 2.对自动化.数据化感兴趣. ...

  4. Javascript Object.defineProperty()

    转载声明: 本文标题:Javascript Object.defineProperty() 本文链接:http://www.zuojj.com/archives/994.html,转载请注明转自Ben ...

  5. Hibernate 之核心接口

    1.持久化和ORM 持久化是指把数据(内存中的对象)保存到可持久保存的存储设备中(如硬盘),主要应用于将内存中的数据存储到关系型数据库中,在三层结构中,持久层专注于实现系统的逻辑层面,将数据使用者与数 ...

  6. sweetalert 快速显示两个提示, 第二个显示不出的问题

    今天在使用 sweetalert 做提示框的时候, 有个操作快速做了两次提示, 发现第二次显示不出: sweetAlert({}, function() { $.get('', function() ...

  7. 在VC++中执行VBS代码

    此代码来自https://blog.csdn.net/zhu2695/article/details/13770671 作者: zhu2695   时间:2013年10月31日 13:08:41 #i ...

  8. Sql语法高级应用之五:使用存储过程实现对明细多层次统计

    前言 前面章节我们讲到了存储过程的基础用法,本章则将一个在项目中实际应用的场景. 在项目中经常会存在这样的需求,例如需要对明细列表进行按组.按级别.按人等进行统计,如果在附带列表的查询条件,又如何实现 ...

  9. 如何使用jQuery实现根据不同IP显示不同的内容

    一些SEM的投放页会针对不同地域做针对性的内容推广,下面我把实现方法分享出来. 一.引用新浪提供的IP查询的js库 <script src="http://int.dpool.sina ...

  10. 解决修改完系统默认python版本后yum不可用的问题!!!!!!

    文章转自: http://www.linuxidc.com/Linux/2013-05/84727.htm #vi /usr/bin/yum 将文件头部的: #!/usr/bin/python 改为: ...