array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'es', ), 'this' => array ( 0 => 'function.rtrim.php', 1 => 'rtrim', ), 'up' => array ( 0 => 'ref.strings.php', 1 => 'Funciones de strings', ), 'prev' => array ( 0 => 'function.quotemeta.php', 1 => 'quotemeta', ), 'next' => array ( 0 => 'function.setlocale.php', 1 => 'setlocale', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'es', 'path' => 'reference/strings/functions/rtrim.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
rtrim — Retira los espacios en blanco (u otros caracteres) del final de un string
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:
32
(0x20
)), un espacio ordinario.
9
(0x09
)), un tabulador.
10
(0x0A
)), una nueva línea (line feed).
13
(0x0D
)), un retorno de carro.
0
(0x00
)), el byte NULL
.
11
(0x0B
)), un tabulador vertical.
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.
Devuelve el string modificado.
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"