Funciones de strings
PHP Manual

rtrim

(PHP 4, PHP 5)

rtrim — Retira los espacios en blanco (u otros caracteres) del final de un string

Descripción

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

Esta función devuelve un string con los espacios en blanco retirados del final de str.

Sin el segundo parámetro, rtrim() retirará estos caracteres:

Parámetros

str

El string de entrada.

character_mask

Se puede también especificar los caracteres que se desean retirar por medio del parámetro character_mask. Simplemente se listan todos los caracteres que se quieren retirar. Con .. se puede especificar un rango de caracteres.

Valores devueltos

Devuelve el string modificado.

Ejemplos

Ejemplo #1 Ejemplo de uso de rtrim()

<?php

$text 
= "\t\tThese are a few words :) ...  ";
$binary = "\x09Example string\x0A";
$hello  = "Hello World";
var_dump($text, $binary, $hello);

print 
"\n";

$trimmed = rtrim($text);
var_dump($trimmed);

$trimmed = rtrim($text, " \t.");
var_dump($trimmed);

$trimmed = rtrim($hello, "Hdle");
var_dump($trimmed);

// retira los caracteres ASCII de control al inicio de $binary
// (de 0 a 31 inclusive)
$clean = rtrim($binary, "\x00..\x1F");
var_dump($clean);

?>

El resultado del ejemplo sería:

string(32) "        These are a few words :) ...  "
string(16) "    Example string
"
string(11) "Hello World"

string(30) "        These are a few words :) ..."
string(26) "        These are a few words :)"
string(9) "Hello Wor"
string(15) "    Example string"

Ver también


Funciones de strings
PHP Manual