라벨이 PHP인 게시물 표시

PHP mysqli_connect: authentication method unknown to the client [caching_sha2_password]

Open a File C:\ProgramData\MySQL\MySQL Server 8.0\my.ini and Edit like this # The default authentication plugin to be used when connecting to the server #default_authentication_plugin=caching_sha2_password default-authentication-plugin=mysql_native_password

nginx 403 Forbidden Error 에러 해결법

C:\nginx\conf\nginx.conf > Open 45 line location / { root html; index index.html index.htm index.php; } 64 line location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME c:/nginx/html$fastcgi_script_name; include fastcgi_params; }

PHP 메모리 부족 해결법

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 64 bytes) in ... 1. php.ini > 393 line memory_limit = 128M or 2. *.php file ini_set('memory_limit', '256M'); // 또는 ini_set('memory_limit', '-1'); http://php.net/memory-limit

PHP 객체지향 프로그래밍 OOP

객체지향 OOP = Object Oriented Programming 절치지향 POP = Process Oriented Programming ! 현실의 문제와 아이디어를 프로그램으로 구현해야 하는 것이 있다면 객체와 객체의 상태, 객체의 행위를 정의하고 구현하면 된다. # 객체 프로그램은 복잡하지 않다. 유지보수가 쉽다. 재사용 하기 쉽다. @ 객체지향 프로그램의 특징 1. 추상화(Abstraction) 2. 상속성(Inheritance) 3. 캡슐화(Encapsulation) 4. 다형성(Polymorphism) 5. 동적바인딩(Dynamic Binding) 추가 및 수정중

PHP 정규 표현식 함수 정리

/************************************* PHP 정규 표현식 함수 정리 http://php.net/manual/en/ref.regex.php **************************************/ /* 정규 표현식 규칙 https://en.wikipedia.org/wiki/Regular_expression . 어떤 한 글자 a.c = a 와 c 사이의 어떤 한 글자 ex) abc, a8c, arc .ac = ac 앞에 어떤 한 글자 ex) zac, 5ac * 0 또는 하나 이상의 한 글자 a*c = c 앞에 글자가 없거나 또는 c 와 a 사이에 글자가 없거나 하나 이상 ex) c, ac, abc, abbbbc ac* = ac 뒤에 글자가 없거나 하나 이상 ex) ac, ac8, acbd123 + 최소 하나 이상의 한 글자 a+c = c 앞에 반드시 a 글자가 하나 이상 ex) ac, abc, aaaabbbbbbbbbbc ? 0 또는 하나의 한 글자 a?c = c 앞에 글자가 없거나 또는 c 와 a 사이에 글자가 없는 ex) c, ac ^ 문자열의 시작 ^ac = ac 로 시작하는 모든 문자열 ex) ac123, ac 8 defg ^a?c = c 나 ac 로 시작하는 모든 문자열 ex) cdefg 123, ac 123 $ 문자열의 끝 ac$ = ac 로 끝나는 모든 문자열 ex) zyxw 123 ac, fold ac a?c+$ = c 나 ac 로 시작하고 하나 이상의 c 로 끝나는 모든 문자열 ex) c, ac, cc, ccccc, acccccccccccc [] 대괄호 안에 있는 문자열 중에서 하나의 문자 [a-z] = 영어 소문자 [a-zA-Z] = 영어 소문자와 대문자 [0-9] = 숫자 {} 중괄호 안에 반복할 문자나 문자열의 갯수 a{3}c = aaac 와 같이 a 의 갯수가 3개인것을 찾음 () 소괄호 안에 있는 글자들을 그룹으로 묶음 a(bc){2} = a 뒤에 bc 가 두개인 것 e...

PHP 수학 연산 함수 정리

/************************************* PHP 수학 연산 함수 정리 http://php.net/manual/en/ref.math.php **************************************/ /* 숫자의 절대값을 반환 abs number = abs(mixed_number) http://php.net/manual/en/function.abs.php */ echo abs(-4.2); // 4.2 (double/float) echo abs(5); // 5 (integer) echo abs(-5); // 5 (integer) /* 숫자의 반올림한 값을 반환 round float = round(float_val) http://php.net/manual/en/function.round.php PHP_ROUND_HALF_UP PHP_ROUND_HALF_DOWN PHP_ROUND_HALF_EVEN PHP_ROUND_HALF_ODD */ echo round(3.4); // 3 echo round(3.5); // 4 echo round(3.6); // 4 echo round(3.6, 0); // 4 echo round(1.95583, 2); // 1.96 echo round(1241757, -3); // 1242000 echo round(5.045, 2); // 5.05 echo round(5.055, 2); // 5.06 echo round(9.5, 0, PHP_ROUND_HALF_UP); // 10 echo round(9.5, 0, PHP_ROUND_HALF_DOWN); // 9 echo round(9.5, 0, PHP_ROUND_HALF_EVEN); // 10 echo round(9.5, 0, PHP_ROUND_HALF_ODD); // 9 echo round(8.5, 0, PHP_ROUND_HALF_UP); // 9 echo round(8...

PHP 변수관련 함수 정리

/* 변수의 데이터타입을 반환 gettype string = gettype(mixed_var) http://php.net/manual/en/function.gettype.php */ $data = array(1, 1.0, NULL, new stdClass, 'foo'); foreach ($data as $value) { echo gettype($value), " / "; } /* 변수가 boolean 타입 변수인지 여부를 반환 is_bool bool = is_bool(mixed_var) http://php.net/manual/en/function.is-bool.php */ $a = false; $b = 0; // Since $a is a boolean, it will return true if (is_bool($a) === true) { echo "Yes, this is a boolean"; } // Since $b is not a boolean, it will return false if (is_bool($b) === false) { echo "No, this is not a boolean"; } /* 변수가 부동소수형 타입의 변수인지 여부를 반환 is_float, is_double, is_real bool = is_float(mixed_var) http://php.net/manual/en/function.is-float.php http://php.net/manual/en/function.is-double.php http://php.net/manual/en/function.is-real.php */ if (is_float(27.25)) { echo "is float"; } else { echo "is not float"; } var_dump(is_float('abc')); // bool(false) ...

PHP 배열 함수 정리

function pre($val){ echo ' '; print_r($val); echo ' '; } /* 배열생성 array array = array(mixed) http://php.net/manual/en/function.array.php */ $arr = array(1,2,3,4,5,6); pre($arr); $arr = array('a'=>'apple','b'=>'banana','c'=>'cherry'); pre($arr); $arr = array('one',5=>'two','three'); pre($arr); $arr = array(1,3,2=>8,4,0=>6); pre($arr); $arr = array('a'=>'apple','b'=>'banana','c'=>'cherry','d'=>array('do'=>array('dol'=>'dolphin','dou'=>'double'),'dr'=>'dragon','du'=>'duck','dw'=>'dwarf')); pre($arr); /* 배열의 원소를 변수에 할당 list array = list(mixed) http://php.net/manual/en/function.list.php */ $alphabet = array('apple','banana','coffee','dance','elf...

PHP print_r() 줄맞춤

// HTML 태그가 그대로 출력 function pre($val){ echo '<pre>'; print_r($val); echo '</pre>'; } // HTML 태그가 실행됨 function xmp($val){ echo '<xmp>'; print_r($val); echo '</xmp>'; }

PHP URL 함수 정리

/* URL을 파싱하여 배열로 반환 parse_url array = parse_url(string_url) http://php.net/manual/en/function.parse-url.php */ $url = "http://php.net:8080/manual/en/function.parse-url.php?id=value1&pw=value2#anchor"; print_r(parse_url($url)); echo parse_url($url, PHP_URL_PATH); $ftp = parse_url("ftp://id:password@ftp.php.net"); print_r($ftp); /* URL을 통해 전송되는 문자열을 인코딩 urlencode string = urlencode(string_str) http://php.net/manual/en/function.urlencode.php */ $url1 = " click "; $url2 = " click "; echo $url1; echo $url2; /* 인코딩된 문자열을 디코딩 urldecode string = urldecode(string_str) http://php.net/manual/en/function.urldecode.php */ $query = "id=A&password=B+and+C"; foreach (explode('&', $query) as $chunk) { $param = explode("=", $chunk); if ($param) { printf("Value for parameter \"%s\" is \"%s\" \n", urldecode($param[0]), urldecode($param[1])); } } /* RFC 1738 규약에 따라 URL을 인코딩 ...

PHP 디렉토리 함수 정리

/* opendir, closedir resource = opendir(string_path) void closedir(resource_dir_handle) http://php.net/manual/en/function.opendir.php http://php.net/manual/en/function.closedir.php */ $dir = "../public_html/"; // 알고 있는 디렉토리를 열어서, 내용을 읽어들이는 작업입니다. if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { echo "filename: $file : filetype: " . filetype($dir.$file); } closedir($dh); } } /* readdir string = readdir(resource_dir_hendle) http://php.net/manual/en/function.readdir.php */ if ($handle = opendir('test/')) { echo "Directory handle : " . $handle; echo "Files : "; /* 디렉토리 안을 루프하는 올바른 방법입니다. */ while (false !== ($file = readdir($handle))) { echo $file; } /* 디렉토리 안을 루프하는 *잘못된* 방법입니다. */ while ($file = readdir($handle)) { echo $file; } closedir($handle); } /* rewinddir void = rewinddir(resource_dir_handle) ...

PHP 파일 시스템 함수 정리

// http://www.gnu.org/licenses/gpl-3.0.txt $filename = "test.txt"; /* fopen resource_handle = fopen(string_filename, string_mode) http://php.net/manual/en/function.fopen.php - mode r : read, pointer Begin r+ : read, write, pointer Begin w : write, erase, create new file, pointer End w+ : write, read, pointer End a : add, write, create new file, pointer End a+ : add, write, read, pointer End x : creat new file, write, pointer Begin x+ : read, write, pointer Begin c : write, pointer Begin c+ : read, write, pointer Begin */ $handle = fopen($filename,"r"); // chmod 777 test, "D:\\test\\test.txt" if ($handle) { echo "file Opened."; } else { die("open Failed."); } /* fread string = fread(resource_handle, int_length) http://php.net/manual/en/function.fread.php */ $handle = fopen($filename,"r"); $temp = fread($handle, 100); echo $temp; /* fwrite, fputs int = fwrite(resource_handle, string, int) int = fputs(resource_handle,...

PHP 문자열 함수 정리

/* nl2br string = nl2br(string) http://php.net/manual/en/function.nl2br.php */ echo nl2br("ABCD \n EFG \n\r"); echo nl2br("HIJK \r LMN \r\n"); /* echo void = echo(string) http://php.net/manual/en/function.echo.php */ echo "ABCDEFG \n"; echo "HIJK","LMN","\n"; echo "OPQR STU \n"; echo ("VWXYZ"." ** \n"); echo <<< ALPHABET ABCDEFGHIJKLMN OPQRSTUVWXYZ. ALPHABET; $flag = TRUE; echo $flag ? "TRUE" : "FALSE"; /* print int = print(string) http://php.net/manual/en/function.print.ph */ $w = "WORLD"; print("HELLO~ $w !"); /* sprintf string = sprintf(string, mixed, mixed) http://php.net/manual/en/function.sprintf.php */ $num = 5; $location = 'tree'; $format = 'There are %d monkeys in the %s'; echo sprintf($format, $num, $location); /* printf int = printf(string, mixed) http://php.net/manual/en/function.printf.php */ printf("%d...

PHP 날짜,시간 함수

/* checkdate bool = checkdate(int month, int day, int year) http://php.net/manual/en/function.checkdate.php */ $valid_date = checkdate(12,31,1999); if($valid_date) { echo "YES"; } else { echo "NO"; } /* time int = time() http://php.net/manual/en/function.time.php */ $nextWeek = time() + (7 * 24 * 60 * 60); echo $nextWeek; /* mktime int = mktime(int hour, int minute, int second, int month, int day, int year, int is_dst) http://php.net/manual/en/function.mktime.php */ $maketime = mktime(); echo $maketime; $maketime = mktime(10,10,30,12,31,1999); echo $maketime; /* date string = date(string format, int timestamp) http://php.net/manual/en/function.date.php */ $maketime = mktime(10,10,30,01,01,2000); // Year echo date("L", $maketime); // leap year 1 true, 0 false echo date("Y", $maketime); // year 4 digits, 2000 echo date("y", $maketime); // year 2 digits, 00 // Month echo date("F", $maketime); // month full text, January ec...

PHP 함수와 클래스의 기본

$a = 100; $b = 10; $c = 1; /* Call by Value */ // Return One Value function method1($a, $b) { $c = $a + $b; return $c; } echo " function1 = " . method1($a,$b); // Return Some Value function method2($a, $b, $c) { $a++; $b++; $c++; return array($a,$b,$c); } list($x,$y,$z) = method2($a,$b,$c); echo " function2 = $x / $y / $z "; /* Call by Reference */ function foo(&$str) { $str .= "world"; } function swap(&$a,&$b) { $temp = $b; $b = $a; $a = $temp; } echo "\$a=" . $a . " \$b=" . $b; swap($a,$b); echo "\$a=" . $a . " \$b=" . $b; $str = "hello~ "; echo $str; foo($str); echo $str; /* Class */ class Class1 { function method1() { echo __FUNCTION__; } function method2() { echo __METHOD__; } } $obj = new Class1(); $obj->method1(); $obj->method2();

PHP 제어문 정리

$i = 0; $a = 1; $b = 2; $c = 3; // IF , ELSE if ($a > $b) { echo "1 > 2"; } else if ($b > $c) { echo "2 > 3"; } else if ($c > $a) { echo "3 > 1"; } else { echo "3 0); // FOR for($i=0; $i 0) { if ($i == 5) { echo "Break! \$i = " . $i; break; } echo $i; $i--; } // CONTINUE for($i=0; $i 1, "b"=>2, "c"=>3); foreach($abc as $value) { echo $value . " "; } foreach($abc as $key=>$value) { echo $key . " = " . $value . " "; } // INCLUDE, REQUIRE include "test.php"; require "test.php";

PHP 비교 연산자

/* == === != = */ $a = 1; $b = 2; // FALSE if ($a == $b) { echo "TRUE"; } else { echo "FALSE"; } // FALSE if ($a === $b) { echo "TRUE"; } else { echo "FALSE"; } // TRUE if ($a != $b) { echo "TRUE"; } else { echo "FALSE"; } // TRUE if ($a $b) { echo "TRUE"; } else { echo "FALSE"; } // TRUE if ($a $b) { echo "TRUE"; } else { echo "FALSE"; } // TRUE if ($a = $b) { echo "TRUE"; } else { echo "FALSE"; }

PHP 논리 연산자

/* and && or || xor ^ ! */ $a = 1; $b = ""; // FALSE // $a and $b if ($a && $b) { echo "TRUE"; } else { echo "FALSE"; } // TRUE // $a or $b if ($a || $b) { echo "TRUE"; } else { echo "FALSE"; } // TRUE // $a xor $b if ($a ^ $b) { echo "TRUE"; } else { echo "FALSE"; } // TRUE if (!$b) { echo "TRUE"; } else { echo "FALSE"; } // FALSE if (TRUE && FALSE) { echo "TRUE"; } else { echo "FALSE"; }

PHP 대입 연산자

/* = += -= *= /= */ $a = 5; echo $a; $a +=5; echo $a; $a -=2; echo $a; $a *=2; echo $a; $a /=8; echo $a;

PHP 문자열 연산자

$a = "ABCD"; $b = "EFG"; $c = "HIJK"; $str = $a.$b.$c; echo $str; $a .= "-123456789"; echo $a;