|
 |
14³â Àü |
word_split
¹®ÀÚ¸¦ $cnt °³¼ö¸¸Å À߶ó ¹è¿¿¡ ´ã´Â´Ù
array word_split ( string $str, int $cnt [, bool $mod ] )
-------------------------------------------------------------
$str = ¹®ÀÚ¿
$cnt = ÀÚ¸¦ °³¼ö
$mode = true = $cnt °³¼ö¸¸Å °è¼Ó Ãß°¡ ÇÔ, false = »ç¿ë¾ÊÇÔ
-------------------------------------------------------------
¿¹Á¦ 1
$str = "1111111";
$array = word_split($str, 2, false);
print_r($array);
°á°ú 1
Array
[0] = 11
[1] = 11
[2] = 11
[3] = 1
¿¹Á¦ 2
$str = "1111111";
$array = word_split($str, 2, true);
print_r($array);
°á°ú 2
Array
[0] = 11
[1] = 1111
[2] = 111111
[3] = 1111111
-------------------------------------------------------------
function word_split($str, $cnt, $mode="")
{
$cnt = (int)$cnt;
$strlen = strlen($str);
$total_str = $strlen / $cnt;
$arr = array();
if ( $mode )
{
$mode_array = array("true", "false");
if ( ! strlen( array_search( $mode, $mode_array ) ) )
return die( " mode ´Â true ³ª false µÑÁß Çϳª¸¸ ÀÔ·ÂÇϼ¼¿ä" );
}
else
{
$mode = false;
}
for ( $i = 0; $i < $total_str; $i++ )
{
if ( $mode == '' ) $array[$i] = substr( $str, $i * $cnt, $cnt );
elseif ( $mode ) $array[$i] = substr( $str, 0, ( $i * $cnt ) + $cnt );
}
return $array;
}
|
|
̵̧ : 280 |
̵̧
¸ñ·Ï
|
|