쪼개기 한판 정보
쪼개기 한판관련링크
본문
<?
// 제가 써먹을려다 보니.....
// 출처 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>';
?>
추천
0
0
댓글 3개
쪼개기?? 먼말인지;;ㅠㅠ
아~~ ^^ 그냥 제가 한말이구요..
문자|문자2|문자3............... 함수관련 얘기여요.. ㅡ,,ㅡ;;
다음부터 속어는 안쓸게요....ㅠㅠ
문자|문자2|문자3............... 함수관련 얘기여요.. ㅡ,,ㅡ;;
다음부터 속어는 안쓸게요....ㅠㅠ
제가..조금 모질한가봐요 ㅠㅠ ㅎㅎ^^