|
|
 |
chunk_split (PHP 3 >= 3.0.6, PHP 4, PHP 5) chunk_split -- Divide una cadena en trozos más pequeños Descripciónstring chunk_split ( string cadena [, int tamano_trozo [, string final]] )
Se puede utilizar para trocear una cadena en pedazos más pequeños,
lo que es útil, p.ej., para convertir la salida de la función base64_encode a la semántica
del RFC 2045. Inserta la cadena final (que por defecto es "\r\n") cada
tamano_trozo (por defecto vale 76) caracteres.
Devuelve la nueva cadena y la cadena original permanece intacta.
Ejemplo 1. Ejemplo de chunk_split() |
<?php
$nueva_cadena = chunk_split(base64_encode($datos));
?>
|
|
Vea también str_split(),
explode(), split(),
wordwrap() y
RFC 2045.
chris AT w3style.co DOT uk
14-Aug-2006 12:32
I'm not sure what versions this also occurs in but the output of chunk_split() in PHP 5.0.4 does not match the output in other versions of PHP.
In all versions of PHP I have used, apart from 5.0.4 chunk_split() adds the separator (\r\n) to the end of the string. But in PHP 5.0.4 this does not happen. This had a fairly serious impact on a library I maintain so it may also affect others who are not aware of this.
xamine at gmail dot com
04-Jun-2006 11:06
In reply to "adrian at zhp dot inet dot pl" digit grouping function:
<?php
$number = strrev(chunk_split (strrev($number), 3,' '));
?>
There is a much more simple way of doing this, by using the built-in number_format() function.
<?php
$number = number_format($number,2,"."," ");
?>
kevin @t hyguard,com
03-Oct-2005 07:08
Not quite completely obvious, but...
you can un_chunk_split() by:
$long_str = str_replace( "\r\n", "", $chunked_str );
harish at thespitbox dot net
30-Jul-2005 05:45
another way to group thousands in a number, which is much simpler, is built into PHP :)
www.php.net/number_format
adrian at zhp dot inet dot pl
08-Jul-2005 02:28
If you need to output number formated with thousand's separator, just use it:
$number = strrev(chunk_split (strrev($number), 3,' '));
If $number is '1234567', result is '1 234 567'.
Kevin
25-Jun-2005 04:10
To phpkid:
This is a much simpler solution.
<?php
function longWordWrap($string) {
$string = str_replace("\n", "\n ", $string); $words = explode(" ", $string); foreach ($words as $word) {
$outstring .= chunk_split($word, 12, " ") . " ";
}
return $outstring;
}
?>
Chris
15-Jun-2005 02:18
@phpkid:
You can avoid such long complex code and just use some CSS stuff.
Just add style="table-layout:fixed" in your <td > tag and your problem will be solved.
ciao
phpkid
28-May-2005 10:47
Well I have been having issues with a shoutbox I am coding it would keep expanding the <TD> if there were large words in it but I fixed it with this:
function PadString($String){
$Exploded = explode(" ", $String);
$Max_Parts = count($Exploded);
$CurArray = 0;
$OutString = '';
while($CurArray<=$Max_Parts)
{
$Peice_Size = strlen($Exploded[$CurArray]);
if($Peice_Size>15)
{
$OutString .= chunk_split($Exploded[$CurArray], 12, " ");
$CurArray++;
} else {
$OutString .= " ".$Exploded[$CurArray];
$CurArray++;
}
}
return $OutString;
}
mv@NOSPAM
24-Jan-2004 07:39
the best way to solve the problem with the last string added by chunk_split() is:
<?php
$string = '1234';
substr(chunk_split($string, 2, ':'), 0, -1);
?>
Danilo
10-Dec-2003 02:51
>> chunk_split will also add the break _after_ the last occurence.
this should be not the problem
substr(chunk_split('FF99FF', 2, ':'),0,8);
will return FF:99:FF
sbarnum at pointsystems dot com
20-Apr-2001 07:46
[Editor's note: You can always use wordwrap('FF99FF', 2, ':', 2); to avoid this]
chunk_split will also add the break _after_ the last occurence. So, attempting to split a color into base components,
chunk_split('FF99FF', 2, ':');
will return FF:99:FF:
| |
| | Citas célebres | Hay que tener cuidado al elegir los enemigos, porque uno termina pareciéndose a ellos. Jorge Luis Borges Escritor argentino (1899-1986) | | Citas en tu mail | | ©Contenidos Gratis |
| Chiste de... Camareros | | Ruta del bacalao | Esto es uno que se va a hacer la "ruta del bacalao" de discoteca en discoteca y, al cabo del rato, le entra al tío una sed de cagarse.
Total, que se llega a la barra y le dice al camarero:
- ¿Me das una botella de agua mineral?
- ¿De qué marca la quieres?
- Humm... No se, ¿cuál me recomiendas?
- Puees... "Lanjarón", que nutre y fortalece el corazón.
- ¿Si? ¡Pues entonces ponme "BEZOYA"!!! | | Chistes en tu mail | | ©ContenidosGratis |
| Inicio | Acción | Estrategia | Palabras | Puzzles | Solitarios | Foro Trucos |  | Cake Mania Jugadores: 6835 Categoría del juego: Acción Objetivo del juego: Ayuda a Jill a recuperar la pastelería de su abuela llevando su propia pastelería; consigue clientes y gana dinero. |
|  | Rainbow Web Jugadores: 2199 Categoría del juego: Puzzles Objetivo del juego: Rompe un pegajoso hechizo y salva un reino de fantasía en Rainbow Web. Tendrás toneladas de diversión mientras juegas a este mágico desafío para la mente. |
|  | Mahjongg Fortuna Jugadores: 12462 Categoría del juego: Solitarios Objetivo del juego: Velocidad y habilidad mental son las armas más importantes en esta versión de un antiguo juego asiático. Despeja el tablero lo antes posible haciendo clic en las fichas iguales y gánate la fama eterna de la puntuación más alta. |
|  | Chainz 2 Jugadores: 6955 Categoría del juego: Puzzles Objetivo del juego: Entra en el mundo de las combinaciones con Chainz 2: Relinked, emocionante secuela del exitazo del año pasado, Chainz. Gira eslabones y crea combinaciones de 3 ó más. |
|  | Delicious Jugadores: 4405 Categoría del juego: Acción Objetivo del juego: ¿Eres un as de la multitarea? ¿Quieres que tus clientes estén contentos? ¡Pues Delicious es tu juego! Sacia el apetito de los clientes y tenlos contentos; ¡no te arriesgues! |
|  | Bookworm Jugadores: 4568 Categoría del juego: Palabras Objetivo del juego: Junta las letras para formar palabras. ¡Las palabras más largas valen más puntos! |
|  | Zuma Jugadores: 4976 Categoría del juego: Acción Objetivo del juego: Controla el ídolo de la rana de piedra de los antiguos Zuma en este intrigante enigma de acción. ¡Dispara bolas para formar conjuntos de tres, pero si dejas que lleguen a la calavera dorada morirás! |
|  | Jewel of Atlantis Jugadores: 3798 Categoría del juego: Puzzles Objetivo del juego: Descubre la ciudad hundida de la Atlántida y busca valiosos tesoros. Viaja más allá de las profundidades del mar y vive trepidantes aventuras en Jewel of Atlantis. |
|  | Jewel Quest Jugadores: 3727 Categoría del juego: Puzzles Objetivo del juego: Convierte la arena de la antigua selva en oro tan rápido como puedas juntando grupos de 3 elementos. ¡Los grupos más grandes valen más puntos! |
|  | Bejeweled 2 Jugadores: 3659 Categoría del juego: Puzzles Objetivo del juego: Con cuatro modos de juego únicos y fascinantes, nuevas piezas de juego explosivas e imponentes fondos planetarios, Bejeweled 2 es mucho más adictivo que nunca. |
|
|