쪼개기 한판
<?
// 제가 써먹을려다 보니.....
// 출처 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>';
?>
// 제가 써먹을려다 보니.....
// 출처 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개
18년 전
쪼개기?? 먼말인지;;ㅠㅠ
18년 전
아~~ ^^ 그냥 제가 한말이구요..
문자|문자2|문자3............... 함수관련 얘기여요.. ㅡ,,ㅡ;;
다음부터 속어는 안쓸게요....ㅠㅠ
문자|문자2|문자3............... 함수관련 얘기여요.. ㅡ,,ㅡ;;
다음부터 속어는 안쓸게요....ㅠㅠ
18년 전
제가..조금 모질한가봐요 ㅠㅠ ㅎㅎ^^
게시판 목록
그누4 팁자료실
그누보드4와 관련된 팁을 여러분들과 함께 공유하세요.
나누면 즐거움이 커집니다.
나누면 즐거움이 커집니다.
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 3309 | 3년 전 | 1809 | ||
| 3308 | 11년 전 | 2096 | ||
| 3307 |
uPAmJ903
|
6년 전 | 4757 | |
| 3306 |
바른사나이
|
6년 전 | 3276 | |
| 3305 | 6년 전 | 12314 | ||
| 3304 | 7년 전 | 3707 | ||
| 3303 | 7년 전 | 3746 | ||
| 3302 |
지리산초보
|
7년 전 | 13599 | |
| 3301 |
sozet
|
8년 전 | 4907 | |
| 3300 |
sozet
|
8년 전 | 5975 | |
| 3299 |
sozet
|
8년 전 | 10864 | |
| 3298 | 8년 전 | 4020 | ||
| 3297 |
또치하우스
|
8년 전 | 4448 | |
| 3296 | 8년 전 | 11977 | ||
| 3295 |
또치하우스
|
8년 전 | 14989 | |
| 3294 | 8년 전 | 6031 | ||
| 3293 | 8년 전 | 5595 | ||
| 3292 |
|
9년 전 | 5324 | |
| 3291 | 9년 전 | 13685 | ||
| 3290 | 9년 전 | 5057 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기