downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

md5_file> <localeconv
[edit] Last updated: Fri, 07 Jun 2013

view this page in

ltrim

(PHP 4, PHP 5)

ltrimRetira espacios en blanco (u otros caracteres) del inicio de un string

Descripción

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

Retira espacios en blanco (u otros caracteres) del inicio de un string.

Parámetros

str

El string de entrada.

charlist

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

Valores devueltos

Esta función devuelve un string con los espacios en blanco retirados del inicio de str. Sin el segundo parámetro, ltrim() retirará estos caracteres:

  • " " (ASCII 32 (0x20)), un espacio ordinario.
  • "\t" (ASCII 9 (0x09)), un tabulador.
  • "\n" (ASCII 10 (0x0A)), una nueva línea (line feed).
  • "\r" (ASCII 13 (0x0D)), un retorno de carro.
  • "\0" (ASCII 0 (0x00)), el byte NULL.
  • "\x0B" (ASCII 11 (0x0B)), un tabulador vertical.

Historial de cambios

Versión Descripción
4.1.0 Fue agregado el parámetro charlist.

Ejemplos

Ejemplo #1 Ejemplo de uso de ltrim()

<?php

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

print 
"\n";


$trimmed ltrim($text);
var_dump($trimmed);

$trimmed ltrim($text" \t.");
var_dump($trimmed);

$trimmed ltrim($hello"Hdle");
var_dump($trimmed);

// retira los caracteres ASCII de control al inicio de $binary
// (de 0 a 31 inclusive)
$clean ltrim($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(30) "These are a few words :) ...  "
string(7) "o World"
string(15) "Example string
"

Ver también

  • trim() - Elimina espacio en blanco (u otro tipo de caracteres) del inicio y el final de la cadena
  • rtrim() - Retira los espacios en blanco (u otros caracteres) del final de un string



md5_file> <localeconv
[edit] Last updated: Fri, 07 Jun 2013
 
add a note add a note User Contributed Notes ltrim - [6 notes]