Joe Phillips
Joe Phillips

Reputation: 51120

Why does rtrim remove things that aren't on the right?

$word = "shshsh.shshsh";
print(rtrim($word, "sh."));

Output is an empty string when I would have expected it to output the entire string (since "sh." does not appear at the end in this case).

Upvotes: 3

Views: 125

Answers (2)

tkausl
tkausl

Reputation: 14279

The "sh." is a set of characters rather than a string to remove. It'll remove characters from the end of the $word recursively as long as it's a character in [s, h, .], until it hits one that isn't in this list, essentially removing everything in your case.

Upvotes: 9

Alerra
Alerra

Reputation: 1519

From here, the 2nd parameter to rtrim will specify a character mask to remove from the string. In other words, by specifying ".sh" as your character mask, you will remove all instances of ., s, and h separately, yielding the empty string.

Upvotes: 3

Related Questions