|
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net
[Spis]
[A]
[B]
[C]
[D]
[E]
[F]
[G]
[H]
[I]
[J]
[K]
[L]
[M]
[N]
[O]
[P]
[Q]
[R]
[S]
[T]
[U]
[V]
[X]
[W]
[Z]
chunk_split (PHP 3 >= 3.0.6, PHP 4, PHP 5) chunk_split -- Split a string into smaller chunks Descriptionstring chunk_split ( string body [, int chunklen [, string end]] )
Can be used to split a string into smaller chunks which is useful for
e.g. converting base64_encode() output to match RFC
2045 semantics. It inserts end (defaults to
"\r\n") every chunklen characters (defaults to
76). It returns the new string leaving the original string untouched.
Przykład 1. chunk_split() example |
<?php
$new_string = chunk_split(base64_encode($data));
?>
|
|
See also str_split(),
explode(), split(),
wordwrap() and
RFC 2045.
User Contributed Noteskevin @t hyguard,com
04-Oct-2005 04: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 02: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 11: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
26-Jun-2005 01: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 11: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 07: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 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);
?>
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:
|