★ wanayoo — archive 1999 http://fr.php.net/manual/it/function.chunk-split.phpNouvelle recherche | Portail wanayoo
PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<chrconvert_cyr_string>
view the version of this page
Last updated: Wed, 24 Nov 2004

chunk_split

(PHP 3>= 3.0.6, PHP 4 , PHP 5)

chunk_split -- Divide una stringa in segmento più piccoli

Descrizione

string chunk_split ( string body [, int chunklen [, string end]])

Questa funzione può essere utilizzata per suddividere una stringa in segmenti più ridotti, per possono essere utili, ad esempio, nel convertire l'output della funzione base64_encode() in modo da aderire alle specifiche indicate nella RFC 2045. La funzione inserisce end (il default è "\r\n") ad ogni chunklen caratteri (default è 76). La funzione restituisce una nuova stringa lasciando inalterata la stringa originale.

Esempio 1. Esempio di uso di chunk_split()

<?php
// format $data using RFC 2045 semantics
$new_string = chunk_split(base64_encode($data));
?>

Vedere anche str_split(), explode(), split(), wordwrap() e RFC 2045.



add a note add a note User Contributed Notes
chunk_split
Dimitri
23-Nov-2004 04:22
If you need the chunks to be split from the right, you can use the following function:

<? function chunk_split_right($str,$len=3,$delim=',') {
      
$size = strlen($str);
       if(
$size <= $len ) return $str;
       return (
chunk_split_right(substr($str,0,$size-$len),$len,$delim).
      
$delim.substr($str,$size-$len,$len));
   }
?>

This is useful for formating large numbers into human readable strings, e.g.

<? echo chunk_split_right(1234567890); ?>

=> 1,234,567,890
mv@NOSPAM
24-Jan-2004 04: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);
// will return 12:34
?>
Danilo
10-Dec-2003 11: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
21-Apr-2001 04: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:

<chrconvert_cyr_string>
 Last updated: Wed, 24 Nov 2004
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2004 The PHP Group
All rights reserved.
This mirror generously provided by: nexen.net
Last updated: Fri Nov 26 05:15:47 2004 CET