뮤

쪼개기 한판

· 2007-01-26 (금) 21:00:31 · 2432 · 3
<?

// 제가 써먹을려다 보니.....
// 출처 http://au3.php.net/manual/en/function.implode.php

$array = array('test1', 'test2', 'test3');
$comma_separated = implode("|", $array);

echo $comma_separated;

echo '<br><br><br>';

$total = count($array); // array count

echo '<br><br><br>';
$comma_separated = explode("|", $comma_separated);

for($i=0;$i<$total;++$i){
echo $comma_separated[$i];
echo '<br>';
}


///////////////////////////////////////////////////
echo '<br><br><br>';

function text_array($array) {
switch (count($array)) {
case 0:
return '';
case 1:
return array_pop($array);
default:
$last = array_pop($array);
return implode('|', $array) . '|' . $last;
}
}


$array = array('test1', 'test2', 'test3','test4');
echo text_array($array);
echo '<br><br><br>';

///////////////////////////////////////////

function text_array2($array) {
switch (count($array)) {
case 0:
return '';
case 1:
return array_pop($array);
default:
$last = array_pop($array);
return implode('|', $array).'/'.$last; // 요기..........포인트
}
}

$array = array('test1', 'test2', 'test3','test4');
echo text_array2($array);
echo '<br><br><br>';

/////////////////////////////////////






function implode_with_keys($array, $glue, $is_query = false) {
if($is_query == true) {
return str_replace(array('[', ']', '&'), array('%5B', '%5D', '&'), http_build_query($array));

} else {
return urldecode(str_replace("&", $glue, http_build_query($array)));

}

}



echo implode_with_keys(array('a' => 'foo bar', 'b' => 'more text'), '|');


echo '<br><br><br>';

///////////////////////////////////////////////////////////////

function english_list($array, $oxfordComma=0)
{
$optionalComma = ( $oxfordComma ) ? "," : "";
$str = "";
$size = count( $array );
$i = 0;
foreach ( $array as $item ) {
$str .= $item;
$i++;
if ( $i < $size - 1) $str .= ", ";
elseif ( $i == $size - 1) $str .= $optionalComma." and ";
}
return $str;
}

// test the comma separated list function
echo english_list( array(), 1 )."<br>";
echo english_list( array("foo"), 1 )."<br>";
echo english_list( array("foo", "bar"), 0 )."<br>";
echo english_list( array("a" => "foo", "b" => "bar", "c" => "foobar"), 1 )."<br>";
echo english_list( array("foo", "bar", "foobar", "barfoo"), 0 )."<br>";

echo '<br><br><br>';

///////////////////////////////////////////////////////////

$val[1]="one";
$val[2]="two";
$val[0]="zero";
ksort($val); // 포인트
echo implode("|",$val);


///////////////////////////////////////////////////////////
echo '<br><br><br>';



?>
|

댓글 3개

쪼개기?? 먼말인지;;ㅠㅠ
아~~ ^^ 그냥 제가 한말이구요..

문자|문자2|문자3............... 함수관련 얘기여요.. ㅡ,,ㅡ;;

다음부터 속어는 안쓸게요....ㅠㅠ
제가..조금 모질한가봐요 ㅠㅠ ㅎㅎ^^
댓글을 작성하시려면 로그인이 필요합니다.

그누4 팁자료실

3,309건

그누보드4와 관련된 팁을 여러분들과 함께 공유하세요. 나누면 즐거움이 커집니다.

+
제목 글쓴이 날짜 조회
07-01-31 조회 3,446
07-01-31 조회 6,636
07-01-31 조회 3,421
07-01-30 조회 2,618
07-01-30 조회 5,249
07-01-30 조회 3,268
07-01-29 조회 3,252
07-01-27 조회 2,604
07-01-27 조회 2,699
07-01-26 조회 4,336
07-01-26 조회 2,433
07-01-26 조회 7,693
07-01-26 조회 4,705
07-01-25 조회 3,509
07-01-24 조회 3,663
07-01-24 조회 6,572
07-01-24 조회 4,513
07-01-24 조회 2,815
07-01-24 조회 4,444
07-01-24 조회 2,685