Home Backend Development PHP Tutorial PHP函数详细辨析之rtrim函数 By ACReaper

PHP函数详细辨析之rtrim函数 By ACReaper

Jun 13, 2016 am 11:34 AM
rtrim short this

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

string rtrim (string $str [, string $charlist ] )

这个函数很好理解、r表示右边、trim表示修剪、即右边修剪、默认修剪字符str右边的字符。默认修剪空格字符。

而当指定$charlist时、其修剪方法是一个个字符的匹配。

先从$charlist取第一个字符和$str最后一个匹配、如果匹配则删除$str后面那个字符。

不匹配则接着匹配$charlist的下个字符直到、$charlist被扫描一篇且没有匹配则完成右裁剪。

如果有匹配的则从$charlist的头开始重新和新的$str的尾字符一个个匹配。



例子:

<?php // Example 1:   rtrim('This is a short short sentence', 'short sentence');   // returns 'This is a'   // If you were expecting the result to be 'This is a short ',   // then you're wrong; the exact string, 'short sentence',   // isn't matched.  Remember, character-by-character comparison!   // Example 2:   rtrim('This is a short short sentence', 'cents');   // returns 'This is a short short '?> 
Copy after login

2013 09 11

By ACReaper

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How many bytes does short occupy? How many bytes does short occupy? Feb 01, 2023 am 11:37 AM

short occupies 2 bytes; short is a type of integer variable family defined in C language; there are three integer types in C language, namely short, int and long; int is called an integer type, and short is called a short Integer type, long is called long integer type.

Use PHP function 'rtrim' to remove whitespace characters on the right side of a string Use PHP function 'rtrim' to remove whitespace characters on the right side of a string Jul 24, 2023 pm 07:53 PM

Use the PHP function "rtrim" to remove whitespace characters on the right side of a string. When writing PHP programs, we often need to process strings. The string may contain whitespace characters such as spaces, tabs, and newlines. If there are blank characters on the right side of the string, it may cause trouble for our subsequent processing. Fortunately, PHP provides a built-in function "rtrim" that can help us quickly remove whitespace characters on the right side of the string. The following is an example of using the "rtrim" function: $str

An article that understands this point and catches up with 70% of front-end people An article that understands this point and catches up with 70% of front-end people Sep 06, 2022 pm 05:03 PM

A colleague got stuck due to a bug pointed by this. Vue2’s this pointing problem caused an arrow function to be used, resulting in the inability to get the corresponding props. He didn't know it when I introduced it to him, and then I deliberately looked at the front-end communication group. So far, at least 70% of front-end programmers still don't understand it. Today I will share with you this link. If everything is wrong If you haven’t learned it yet, please give me a big mouth.

How to use this method in Java How to use this method in Java Apr 18, 2023 pm 01:58 PM

1. this keyword 1. Type of this: Which object is called is the reference type of that object 2. Usage summary 1. this.data;//Access attribute 2. this.func();//Access method 3.this( );//Call other constructors in this class 3. Explanation of usage 1.this.data is used in member methods. Let us see what will happen if this is not added classMyDate{publicintyear;publicintmonth;publicintday; publicvoidsetDate(intyear,intmonth,intday){ye

Analysis of usage skills of this in jQuery Analysis of usage skills of this in jQuery Feb 22, 2024 pm 08:54 PM

jQuery is a popular JavaScript library widely used for DOM manipulation and event handling in web development. One of the important concepts is the use of this keyword. In jQuery, this represents the DOM element currently being operated on, but in different contexts, the pointer of this may be different. This article will analyze the usage skills of this in jQuery through specific code examples. First, let's look at a simple example:

Detailed explanation of this in JavaScript arrow function Detailed explanation of this in JavaScript arrow function Jan 25, 2024 pm 01:41 PM

The arrow function in JavaScript is a relatively new syntax. It does not have its own this keyword. On the contrary, the this of the arrow function points to the scope object containing it. The impacts are: 1. This in the arrow function is static; 2. Arrow Functions cannot be used as constructors; 3. Arrow functions cannot be used as methods.

What is this? An in-depth analysis of this in JavaScript What is this? An in-depth analysis of this in JavaScript Aug 04, 2022 pm 05:02 PM

What is this? The following article will introduce you to this in JavaScript, and talk about the differences between this in different calling methods of functions. I hope it will be helpful to you!

How does JavaScript change this pointer? Brief analysis of three methods How does JavaScript change this pointer? Brief analysis of three methods Sep 19, 2022 am 09:57 AM

How does JavaScript change this pointer? The following article will introduce to you three methods of changing this pointer in JS. I hope it will be helpful to you!

See all articles