개발 관련/PHP
-
substr_count() 함수개발 관련/PHP 2011. 5. 12. 11:41
int substr_count ( string $haystack , string $needle [, int $offset= 0 [, int $length ]] ) — Count the number of substring occurrences 해당 글에(string $haystack)에 string $needle 글자가 몇번 있는지 세는 함수 [ int $offset -> 몇번째 글 부터 찾을 건지 int $length -> 몇번째 글 까지 찾을 건지 ] $text = 'This is a test'; echo strlen($text); // 14 echo substr_count($text, 'is'); // 2 // the string is reduced to 's is a test', so it prin..
-
urlencode(), urldecode() 함수개발 관련/PHP 2011. 3. 24. 15:33
urlencode (PHP 4, PHP 5) urlencode — 문자열을 URL 인코드 header("Content-Type: text/html; charset=UTF-8"); $userinput= 'encodeing&&인코딩!'; echo urlencode($userinput)." "; --> encodeing%26%26%EC%9D%B8%EC%BD%94%EB%94%A9%21 $useroutput= 'encodeing%26%26%EC%9D%B8%EC%BD%94%EB%94%A9%21'; echo urldecode($useroutput); --> encodeing&&인코딩! 참고사항 urlencode 같은 경우는 [0-9a-zA-z]등은 encode가 되지 않습니다. 한글 및 특수 문자만 인코딩 됩니다. ..
-
join()개발 관련/PHP 2011. 3. 23. 16:58
join (PHP 4, PHP 5) join(separator,array) 별칭: implode() $array = array('lastname', 'email', 'phone'); $comma_separated = join(",", $array); echo $comma_separated; --> lastname,email,phone echo "implode= ". implode(",", $array)." "; --> lastname,email,phone join()함수와 implode() 함수는 같다고 생각이 되네요 implode() 함수의 설명을 보면 string implode ( string $glue , array $pieces ) glue의 기본값은 빈 문자열이고 glue를 두번째 인자로 사용하..
-
htmlentities개발 관련/PHP 2011. 3. 22. 16:33
htmlentities (PHP 4, PHP 5) htmlentities — 해당하는 모든 문자를 HTML 엔티티로 변환 string htmlentities ( string $string [, int $quote_style [, string $charset [, bool $double_encode ]]] ) htmlentities()는 HTML 문자 엔티티에 존재하는 모든 문자를 엔티티로 변환하는 점을 제외하면, htmlspecialchars()와 완전히 동일합니다. 디코드(역변환)하려면 html_entity_decode()를 사용할 수 있습니다. $str = "A 'quote' is bold"; // 출력: A 'quote' is bold echo htmlentities($str); // 출력: A &..
-
Date() 함수개발 관련/PHP 2011. 3. 17. 15:58
echo "현재 시간: ".date('Y-m-d h:i:s')." ";// 현재 시간: 2011-03-17 03:55:06 echo "---------- 일(Day) ---------- "; echo "date('d') = ". date('d') ." ";// 17 echo "date('D') = ". date('D') ." ";// Thu echo "date('j') = ". date('j') ." ";// 17 echo "date('l') = ". date('l') ." ";// Thursday echo "date('N') = ". date('N') ." ";// 4 echo "date('S') = ". date('S') ." ";// th echo "date('w') = ". date('w') ."..
-
chr개발 관련/PHP 2011. 3. 14. 15:01
string chr ( int $ascii ) ascii 에 지정한 문자를 가지는 한 글자의 문자열을 반환합니다. $str = "The string ends in escape:"; $str .= chr(20); /* $str의 마지막에 이스케이프 문자를 추가합니다. */ echo $str." "; // Result: The string ends in escape: //반대로는 int(string $string) $str = "The string ends in escape: "; $str .= ord(''); echo $str." "; // Result: The string ends in escape: 20 출처: http://kr.php.net/manual/kr/function.chr.php
-
addslashes개발 관련/PHP 2011. 3. 9. 15:00
addslashes — 문자열을 슬래시로 인용 보통 DB Insert(Update)시에 사용을 하는 함수로 Ex) $a = ' I'm a Boy' echo addslashes($a); Result : I\'m a Boy 참고사항. php.ini 에서 magic_quotes 설정이 On일 경우에는 GET, POST, GOOKIE등 Request시에 자동으로 addslashes 처리를 하므로 addslashes처리를 또 할경우 중복 이스케이프를 하게 됩니다. 따라서 get_magic_quotes_gpc() 함수로 magic_quotes가 On인지 Off인지를 파악 후에 처리해야 합니다. 위에 예제에서 활용을 하면 echo 전에 if(!get_magic_quotes_gpc()) { echo addslashes..
-
PHP 'getimagesize()' 함수개발 관련/PHP 2010. 3. 29. 10:49
PHP 'getimagesize()' 함수는 이미지의 크기, 형식을 알려줍니다. list($width, $height, $type, $attr) = getimagesize("img/flag.jpg"); echo ""; 위 예에서 처럼 상대경로로 이미지를 정해주면 해당 이미지의 정보를 가로 사이즈, 세로 사이즈, 이미지 형식, 이미지 사이즈 정보 HTML 태그 순으로 반환합니다. 아래는 또 다른 사용예입니다. $img = getimagesize("img/flag.jpg"); $type = $img['mime']; $width = $img[0]; $height = $img[1]; 이미지 형식을 나타내는 정수값은 아래와 같습니다. 1 : 'GIF' 2 : 'JPG' 3 : 'PNG' 4 : 'SWF' 5 : ..