Archive

Posts Tagged ‘php’

배열함수

June 29, 2007 Leave a comment

is_array(), explode(), implode(), split() 그리고 join()을 참조하라.

  • array_change_key_case — Returns an array with all string keys lowercased or uppercased
  • array_chunk — Split an array into chunks
  • array_count_values — 배열 값의 수를 센다.
  • array_diff_assoc — Computes the difference of arrays with additional index check
  • array_diff — 배열의 차이을 계산한다.
  • array_fill — Fill an array with values
  • array_filter — Filters elements of an array using a callback function
  • array_flip — Flip all the values of an array
  • array_intersect_assoc — Computes the intersection of arrays with additional index check
  • array_intersect — 배열의 중복을 계산한다.
  • array_key_exists — Checks if the given key or index exists in the array
  • array_keys — 배열의 모든 키값을 반환한다.
  • array_map — Applies the callback to the elements of the given arrays
  • array_merge_recursive — 재귀적으로 두개 혹은 그 이상의 배열을 병합한다.
  • array_merge — 두개 혹은 그 이상의 배열을 병합한다.
  • array_multisort — 여러개의 배열 혹은 다차원 배열을 정렬한다.
  • array_pad — 주어진 값의 길이만큼 배열을 채운다
  • array_pop — 배열 끝의 요소를 뽑아낸다.
  • array_push — 배열 끝에 하나 혹은 그 이상의 원소를 넣는다.
  • array_rand — 배열에서 하나 혹은 그 이상의 임의의 원소를 가져온다.
  • array_reduce — Iteratively reduce the array to a single value using a callback function
  • array_reverse — 각 엘리먼트를 역순으로 정렬한 배열을 반환한다.
  • array_search — Searches the array for a given value and returns the corresponding key if successful
  • array_shift — 배열의 맨 앞에 있는 원소를 꺼내고 그 원소를 삭제한다
  • array_slice — 배열의 일부를 추출한다.
  • array_splice — 배열의 일부를 삭제하고, 그 위치에 다른 내용을 끼워 넣는다.
  • array_sum — Calculate the sum of values in an array.
  • array_unique — 배열로부터 중복된 값을 제거한다.
  • array_unshift — 배열의 맨 앞에 한 개나 그 이상의 원소를 첨가한다.
  • array_values — 배열의 모든 값들을 반환한다.
  • array_walk — 배열의 개개의 원소에 특정 함수를 적용하여 수행한다.
  • array — 배열을 생성한다
  • arsort — 배열을 역순으로 정렬하고 인덱스의 상관관계를 유지한다.
  • asort — 배열을 정렬하고 index association을 유지한다.
  • compact — 주어진 여러 변수의 이름과 값을 가지는 배열을 만든다.
  • count — 배열 변수의 원소 개수를 구한다.
  • current — 배열의 현재 원소를 돌려준다
  • each — 배열로부터 다음원소의 키와 값 쌍을 반환한다. Return the next key and value pair from an array
  • end — Set the internal pointer of an array to its last element
  • extract — Import variables into the symbol table from an array
  • in_array — Return TRUE if a value exists in an array
  • key — Fetch a key from an associative array
  • krsort — Sort an array by key in reverse order
  • ksort — Sort an array by key
  • list — Assign variables as if they were an array
  • natcasesort — Sort an array using a case insensitive “natural order” algorithm
  • natsort — Sort an array using a “natural order” algorithm
  • next — Advance the internal array pointer of an array
  • pos — Get the current element from an array
  • prev — Rewind the internal array pointer
  • range — Create an array containing a range of integers
  • reset — Set the internal pointer of an array to its first element
  • rsort — Sort an array in reverse order
  • shuffle — Shuffle an array
  • sizeof — Get the number of elements in an array
  • sort — Sort an array
  • uasort — Sort an array with a user-defined comparison function and maintain index association
  • uksort — Sort an array by keys using a user-defined comparison function
  • usort — Sort an array by values using a user-defined comparison function

확장자로 해당 파일의 mime 타입 알아오기

June 26, 2007 Leave a comment

*where : http://www.phpschool.com/gnuboard4/bbs/board.php….

function get_mine_type($exp){
$exp = strtolower($exp);
static $mime_type;
if(!is_array($mime_type)){
$mime_type = array();
$mime_type['dwg']=’application/acad’;
$mime_type['ccad']=’application/clariscad’;
$mime_type['dxf']=’application/dxf’;
$mime_type['mdb']=’application/msaccess’;
$mime_type['doc']=’application/msword’;
$mime_type['bin']=’application/octet-stream’;
$mime_type['pdf']=’application/pdf’;
$mime_type['ai']=’application/postscript’;
$mime_type['ps']=’application/postscript’;
$mime_type['eps']=’application/postscript’;
$mime_type['rtf']=’application/rtf’;
$mime_type['rtf']=’application/rtf’;
$mime_type['xls']=’application/vnd.ms-excel’;
$mime_type['ppt']=’application/vnd.ms-powerpoint’;
$mime_type['cdf']=’application/x-cdf’;
$mime_type['csh']=’application/x-csh’;
$mime_type['csh']=’application/x-csh’;
$mime_type['dvi']=’application/x-dvi’;
$mime_type['js']=’application/x-javascript’;
$mime_type['latex']=’application/x-latex’;
$mime_type['mif']=’application/x-mif’;
$mime_type['xls']=’application/x-msexcel’;
$mime_type['ppt']=’application/x-mspowerpoint’;
$mime_type['tcl']=’application/x-tcl’;
$mime_type['tex']=’application/x-tex’;
$mime_type['texinfo']=’application/x-texinfo’;
$mime_type['texi']=’application/x-texinfo’;
$mime_type['t']=’application/x-troff’;
$mime_type['tr']=’application/x-troff’;
$mime_type['roff']=’application/x-troff’;
$mime_type['man']=’application/x-troff-man’;
$mime_type['me']=’application/x-troff-me’;
$mime_type['ms']=’application/x-troff-ms’;
$mime_type['src']=’application/x-wais-source’;
$mime_type['zip']=’application/zip’;
$mime_type['au']=’audio/basic’;
$mime_type['snd']=’audio/basic’;
$mime_type['aif']=’audio/x-aiff’;
$mime_type['aiff']=’audio/x-aiff’;
$mime_type['aifc']=’audio/x-aiff’;
$mime_type['wav']=’audio/x-wav’;
$mime_type['gif']=’image/gif’;
$mime_type['ief']=’image/ief’;
$mime_type['jpeg']=’image/jpeg’;
$mime_type['jpg']=’image/jpeg’;
$mime_type['jpe']=’image/jpeg’;
$mime_type['tiff']=’image/tiff’;
$mime_type['tif']=’image/tiff’;
$mime_type['png']=’image/png’;
$mime_type['ras']=’image/x-cmu-raster’;
$mime_type['pnm']=’image/x-portable-anymap’;
$mime_type['pbm']=’image/x-portable-bitmap’;
$mime_type['pgm']=’image/x-portable-graymap’;
$mime_type['ppm']=’image/x-portable-pixmap’;
$mime_type['rgb']=’image/x-rgb’;
$mime_type['xbm']=’image/x-xbitmap’;
$mime_type['xpm']=’image/x-xpixmap’;
$mime_type['xwd']=’image/x-xwindowdump’;
$mime_type['gzip']=’multipart/x-gzip’;
$mime_type['zip']=’multipart/x-zip’;
$mime_type['css']=’text/css’;
$mime_type['html']=’text/html’;
$mime_type['htm']=’text/html’;
$mime_type['txt']=’text/plain’;
$mime_type['rtx']=’text/richtext’;
$mime_type['tsv']=’text/tab-separated-values’;
$mime_type['xml']=’text/xml’;
$mime_type['etx']=’text/x-setext’;
$mime_type['xsl']=’text/xsl’;
$mime_type['mpeg']=’video/mpeg’;
$mime_type['mpg']=’video/mpeg’;
$mime_type['mpe']=’video/mpeg’;
$mime_type['mov']=’video/quicktime’;
$mime_type['qt']=’video/quicktime’;
$mime_type['avi']=’video/x-msvideo’;
$mime_type['movie']=’video/x-sgi-movie’;
$mime_type['swf']=’application/x-shockwave-flash’;
}
if(isset($mime_type[$exp])){
return $mime_type[$exp] ;
}else{
return false;
}
}

Tags: ,

include, include_ once, require, require_ once

June 16, 2007 Leave a comment

http://kr2.php.net/manual/kr/function.include.php
http://kr2.php.net/manual/kr/function.include-once.php
http://kr2.php.net/manual/kr/function.require.php
http://kr2.php.net/manual/kr/function.require-once.php

include()문은 특정 파일을 인클루드 하고, 적용시킨다.

이하 내용은 require()에도 적용되는 사항이다. 두가지 구조는 수행실패를 제어하는 방법을 제외하고 모든면에서 동일하다. include()는 Warning을 발생시키는 반면에 require()는 Fatal Error을 발생시킨다. 즉, 파일이 존재하지 않을때 페이지 처리를 중단시키 고자 한다면 require()를 쓰는데 주저할 필요가 없다. include()는 이와같이 동작하지 않으므로 파일이 없더라도 스크립트는 계속 실행될것이다. 또한 적절한 include_path설정인지 확인해야 한다. require한 파일 안에서의 처리 오류는 수행을 멈추지 않는 점에 주의하십시오.

파일을 포함할 경우 가장 먼저 현재 작업 디렉토리에 상대 경로로 include_path를 찾고, 다음으로 현재 스크립트의 디렉토리에 상대 경로로 include_path를 찾습니다. 예를 들어, include_path가 .이고, 현재 작업 디렉토리 /www/에서 include/a.php를 포함하였고, 그 파일 안에 include “b.php”이 존재하면, b.php는 우선 /www/에서 찾고, 다음으로 /www/inclde/에서 찾습니다.

파일이 인클루드 되면, 그 코드를 포함하는 코드는 인클루드가 발생한 줄의 변수 유효 범위를 물려받는다. 호출하는 파일의 그 줄에서 사용되는 어떤 변수도 그 줄부터는 호출된 파일안에서 사용이 가능하다.

include_once()문은 스크립트 수행기간동안 특정파일을 인클루드하고 적용시킨다.

이것은 include()문과 비슷하게 동작한다. 단지 파일의 특정 코드가 이미 인클루되었다면 그 코드는 다시는 인클루드 될수 없다는 차이점만 있다. 이 이름이 제시하듯이 한번만 인클루드할것이다.

include_once()는 특정 스크립트 수행기간동안 동일한 파일이 한번 이상 인클루드되고 적용될지도 모르는 상황에서 사용해야 할것이다. 그리고 함수 중복정의, 변수값 중복 지정 등의 문제를 회피하려면 정확히 한번만 인클루드할 때가 있을것이다.

require()문은 특정 파일을 인클루드하고, 적용시킨다.

require()문은 특정 파일을 인클루드하고, 적용시킨다. 이런 인클루드가 어떻게 동작하는지에 대한 자세한 정보는 include()에 대한 문서에서 설명한다.

require()와 include() 는 수행실패를 제어하는 방법을 제외하고 모든면에서 동일하다. include()는 Warning을 발생시키는 반면에 require()는 Fatal Error을 발생시킨다. 즉, 파일이 존재하지 않을때 페이지 처리를 중단시키 고자 한다면 require()를 쓰는데 주저할 필요가 없다. include()는 이와같이 동작하지 않으므로 파일이 없더라도 스크립트는 계속 실행될것이다. 또한 적절한 include_path설정인지 확인해야 한다.

require_once()문은 스크립트 수행기간 중에 특정파일을 인클루드하고 적용시킨다.

이것은 require()문과 비슷하게 동작한다. 오직 파일의 코드가 이미 인클루드되었다면 다시 인클루드되지 않을것 이라는 차이점이 있다. 이 구문이 어떻게 작용하는지에 대한 정보를 알아보려면 require()함수에 대한 문서를 보세요.

require_once()는 특정 스크립트 수행기간동안 한번이상 인클루드되고 적용될수 있는 상황에서 사용하도록 한다. 그리고 함수 중복 정의와 변수값 중복 지정 등에 대한 문제를 회피하기 위해서는 정확히 한번 인클루드될 필요가 있을것이다.

Tags: ,