2014년 12월 13일 토요일

윈도우 시간 동기화 오류

멀티부팅으로 우분투 리눅스와 윈도우를
하나의 컴퓨터에서 같이 쓰는 바람에 생긴 문제는

우분투에서
/etc/default/rcS 파일의 UTC 값을 no 로 변경

간단하게는
화면 오른쪽위 시계에서 UTC 체크된걸 해제하면 된다.
인터넷으로 시간을 동기화 하려면

콘솔창에서
sudo apt-get install rdate
sudo rdate kr.pool.ntp.org

윈도우 업데이트 이후
컴퓨터 시계 시간이
자꾸만 엉뚱하게 나와
찾아보니

time.windows.com 이게 제대로 작동을 안하고 있었다.

아래 주소로 바꿔주니 잘 작동 !

kr.pool.ntp.org 여기 강추
time.kriss.re.kr 여기도 좋긴한데, IP 제한이 있는듯..

왠만하면 2계층 서버로 바꾸는게 좋을듯 하다.
1계층 서버는 사람이 많이 몰리다보니 자주 뻗는듯.

다른나라 주소를 알고 싶다면, 아래 주소로~



컴퓨터 화면의 오른쪽 아래 시간을 누르고
날짜 및 시간 설정 변경... 이라는 글자를 누르면 창이 하나 뜨는데
인터넷 시간 이라는 글자를 누르고, 설정변경을 누르면 위 그림이 뜬다.
서버(E) : time.windows.com 되어있는걸 kr.pool.ntp.org 이걸로 바꾸고
지금 업데이트를 누르고 확인을 누르면 ~ 끝 !

2014년 12월 12일 금요일

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", "123.456");
printf("%2.2f", "123.4");
printf("%.2f", "3.141592653589793238462643383279502884197169399");

/*
sscanf
mixed = sscanf(string, string mixed)
http://php.net/manual/en/function.sscanf.php
*/
list($year, $month, $day, $serial) = sscanf("SN/19991231-A1234", "SN/%4d %2d %2d-%s%d");
echo "Item $serial was manufactured on: $year-" . $month . "-$day \n";

/*
explode
array = explode(string delimiter, string)
http://php.net/manual/en/function.explode.php
*/
$pizza  = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
echo $pieces[0];
echo $pieces[5];
foreach($pieces as $key=>$value)
{
 echo $value . " ";
}

/*
implode 
string = implode(string, array)
http://php.net/manual/en/function.implode.php
*/
$pieces = array("piece1", "piece2", "piece3");
$pizza = implode(",", $pieces);
echo $pizza;

/*
strcmp
int = strcmp(string, string)
http://php.net/manual/en/function.strcmp.php
*/
$var1 = "Hello";
$var2 = "hello";
if(strcmp($var1, $var2) !== 0) // 0 is equal
{
    echo "$var1 <> $var2";
}
else
{
    echo "$var1 = $var2";
}

/*
strcasecmp
int = strcasecmp(string, string)
http://php.net/manual/en/function.strcasecmp.php
*/
$var1 = "Hello";
$var2 = "hello";
if(strcmp($var1, $var2) !== 0) // 0 is equal
{
    echo "$var1 = $var2";
}
else
{
    echo "$var1 <> $var2";
}

/*
strncmp
int = strncmp(string, string, int)
http://php.net/manual/en/function.strncmp.php
*/
if(strncmp("abc","aBC",2)==0) //if(!strncmp("abc","aBC",1))
{
 echo "equal";
}
else
{
 echo "not equal";
}

/*
strncasecmp
int = strcasecmp(string, string, int)
http://php.net/manual/en/function.strncasecmp.php
*/
if(strcasecmp("abc","aBC",2)==0) //if(!strncmp("abc","aBC",1))
{
 echo "equal";
}
else
{
 echo "not equal";
}

/*
substr
string = substr(string, int, int)
http://php.net/manual/en/function.substr.php
*/
echo substr("abcdefg",1);   // bcdefg
echo substr("abcdefg",0,1); // a
echo substr("abcdefg",-1);  // g
echo substr("abcdefg",-5,2);// cd

/*
strstr, strchr
string = strstr(string, string)
string = strchr(string, string)
http://php.net/manual/en/function.strstr.php
http://php.net/manual/en/function.strchr.php
*/
echo strstr("abcdefg","e");  // efg
echo strchr("YEAR-1999","-");// 1999

/*
stristr
string = stristr(string, string)
http://php.net/manual/en/function.stristr.php
*/
echo stristr("ABCDEFG","e");

/*
strrchr
string = strrchr(string, mixed)
http://php.net/manual/en/function.strrchr.php
*/
echo strrchr("hello1/hello2/hello3","/");

/*
strpos
int = strpos(string, mixed, int)
http://php.net/manual/en/function.strpos.php
*/
echo strpos("abcd/abcd/abcd","/");   // 4
echo strpos("abcd/abcd/abcd","/",5); // 9

/*
strrpos
int = strrpos(string, string, int)
http://php.net/manual/en/function.strrpos.php
*/
echo strrpos("abcd/abcd/abcd","/");    // 9
echo strrpos("abcd/abcd/abcd","/",11); // FALSE

/*
stripos
int = stripos(string, string, int)
http://php.net/manual/en/function.stripos.php
*/
echo stripos("abcd/ABCD/abcd","C"); // 2

/*
strripos
int = strripos(string, string, int)
http://php.net/manual/en/function.strripos.php
*/
echo strripos("abcd/ABCD/abcd","C"); // 12

/*
strlen
int = strlen(string)
http://php.net/manual/en/function.strlen.php
*/
echo strlen("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); // 26

/*
strspn
int = strspn(string, string, int, int)
http://php.net/manual/en/function.strspn.php
*/
echo strspn("12345", "1234567890abcdefghijklmnopqrstuvwxyz");  // 5
echo strspn("vwxyz", "1234567890abcdefghijklmnopqrstuvwxyz", 1,3); // wxy 3

/*
strcspn
int = strcspn(string, string, int, int)
http://php.net/manual/en/function.strcspn.php
*/
echo strcspn("12345", "1234567890abcdefghijklmnopqrstuvwxyz");  // 0
echo strspn("vwxyz", "1234567890abcdefghijklmnopqrstuvwxyz", 1,3); // wxy 3

/*
strnatcmp
int = strnatcmp(string, string)
http://php.net/manual/en/function.strnatcmp.php
*/
$str1 = "img11.png";
$str2 = "img2.png";
echo strcmp($str1,$str2); // -1
echo strnatcmp($str1,$str2); // 1

$arr1 = $arr2 = array("img12.png", "img10.png", "img2.png", "img1.png");

// Standard string comparison
usort($arr1, "strcmp"); // 1 10 12 2
print_r($arr1);

// Natural order string comparison
usort($arr2, "strnatcmp"); // 1 2 10 12
print_r($arr2);

/*
strnatcasecmp
int = strnatcasecmp(string, string)
http://php.net/manual/en/function.strnatcasecmp.php
*/
$str1 = "A.png";
$str2 = "a.png";
echo strcmp($str1,$str2); // -1
echo strnatcmp($str1,$str2); // -1
echo strnatcasecmp($str1,$str2); // 0

$arr1 = $arr2 = array("ABC.png", "abc.png", "aBC.png", "Abc.png");

usort($arr1, "strcmp"); // ABC Abc aBC abc
print_r($arr1);

usort($arr2, "strnatcmp"); // ABC Abc aBC abc
print_r($arr2);

usort($arr2, "strnatcasecmp"); // abc aBC Abc ABC
print_r($arr2);

/*
strtolower
string = strtolower(string)
http://php.net/manual/en/function.strtolower.php
*/
echo strtolower("ABC"); // abc

/*
strtoupper
string = strtoupper(string)
http://php.net/manual/en/function.strtoupper.php
*/
echo strtoupper("abc"); // ABC

/*
ucfirst
string = ucfirst(string)
http://php.net/manual/en/function.ucfirst.php
*/
echo ucfirst("abc"); // Abc

/*
ucwords
string = ucwords(string)
http://php.net/manual/en/function.ucwords.php
*/
echo ucwords("the quick brown fox jumps over the lazy dog"); 
// The Quick Brown Fox Jumps Over The Lazy Dog

/*
strrev
string = strrev(string)
http://php.net/manual/en/function.strrev.php
*/
echo strrev("olleh"); // hello

/*
strtr
string = strtr(string, string, string)
string = strtr(string, array)
http://php.net/manual/en/function.strtr.php
*/
echo strtr("olleh AB", "AB", "XYZ"); // olleh XY
echo strtr("hello apple", "e", "u"); // hullo applu
$arr = array("hello"=>"hell", "apple"=>"open");
echo strtr("hello apple", $arr); // hell open

/*
str_replace
mixed = str_replace(mixed, mixed, mixed)
http://php.net/manual/en/function.str-replace.php
*/
echo str_replace("apple", "world", "hello apple"); // hello world

$food = array("microsoft","banana","cherry","donuts","egg");
$arr = str_replace("microsoft","apple",$food);
print_r($arr); // apple, banana, cherry, donuts, egg

$search = array("microsoft","egg","cherry","banana","donuts");
$replace = array("soft-icecream","milk","berry");
$arr = str_replace($search,$replace,$food);
print_r($arr); // soft-icecream, ,berry, ,milk

$alphabet = array("a","b","c","d","e","f","g");
$search = array("a","b","c","d");
$replace = array("A","B","C");
$arr = str_replace($search,$replace,$alphabet,$count);
print_r($arr); // A, B, C, ,e, f, g
echo $count; // 4

/*
str_ireplace
mixed = str_ireplace(mixed, mixed, mixed)
http://php.net/manual/en/function.str-ireplace.php
*/
echo str_ireplace("ABC","XYZ","123abc"); // 123XYZ

/*
trim
string = trim(string)
http://php.net/manual/en/function.trim.php
*/
$text   = "\x0B\n\t\r\0 1 2 3 4 5 ";
var_dump($text); // 16
var_dump(trim($text)); // 9

/*
ltrim
string = ltrim(string)
http://php.net/manual/en/function.ltrim.php
*/
$text   = "\x0B\n\t\r\0 1 2 3 4 5 ";
var_dump($text); // 16
var_dump(ltrim($text)); // 10

/*
rtrim, chop
string = rtrim(string)
string = chop(string)
http://php.net/manual/en/function.rtrim.php
*/
$text   = "\x0B\n\t\r\0 1 2 3 4 5 ";
var_dump($text); // 16
var_dump(rtrim($text)); // 15
var_dump(chop($text)); // 15

/*
quotemeta
string = quotemeta(string)
http://php.net/manual/en/function.quotemeta.php
*/
$text   = " START . \ + * ? [ ^ ] ( $ ) END ";
echo $text; // START . \ + * ? [ ^ ] ( $ ) END
echo quotemeta($text); // START \. \\ \+ \* \? \[ \^ \] \( \$ \) END

/*
ord
int = ord(string)
http://php.net/manual/en/function.ord.php
*/
$ASCII = "A";
echo ord($ASCII); // 65

/*
chr
string = chr(int ascii)
http://php.net/manual/en/function.chr.php
*/
$ASCII = "65";
echo chr($ASCII); // A

/*
parse_str
void = parse_str(string, array)
http://php.net/manual/en/function.parse-str.php
*/
$str = "id=a&arr[]=b+c&arr[]=d";
parse_str($str);
echo $id;  // a
echo $arr[0]; // b c
echo $arr[1]; // d
parse_str($str, $output);
echo $output["id"];  // a
echo $output["arr"][0]; // b c
echo $output["arr"][1]; // d

/*
strip_tags
string = strip_tags(string, string)
http://php.net/manual/en/function.strip-tags.php
*/
$html = "The  Quick Brown Fox  Jumps Over The Lazy Dog. ";
echo strip_tags($html);
echo strip_tags($html,"<b>");

/*
str_repeat
string = str_repeat(string, int)
http://php.net/manual/en/function.str-repeat.php
*/
echo str_repeat("*", 10); // **********

/*
str_pad
string = str_pad(string, int, string, int)
http://php.net/manual/en/function.str-pad.php
*/
$str = "i";
echo str_pad($str, 5);                     // i
echo str_pad($str, 5, "*");                // i****
echo str_pad($str, 5, "*", STR_PAD_RIGHT); // i****
echo str_pad($str, 5, "*", STR_PAD_LEFT);  // ****i
echo str_pad($str, 5, "*", STR_PAD_BOTH);  // **i**

/*
substr_count
int = substr_count(string, string, int, int)
http://php.net/manual/en/function.substr-count.php
*/
$text = 'This is a test';
echo strlen($text); // 14
echo substr_count($text, 'is'); // 2 : This is a test
echo substr_count($text, 'is', 3); // 1 : s is a test
echo substr_count($text, 'is', 3, 3); // 0 : s i
echo substr_count($text, 'is', 5, 10); // error : 5+10 > 14

/*
crypt
string = crypt(string, salt)
http://php.net/manual/en/function.crypt.php
*/
$salt = "ab";
$password = "1234";
echo crypt($password);
echo crypt($password,$salt);

if (CRYPT_STD_DES == 1)
{
    echo "Standard DES: " . crypt("1234", "rl"); // 2 digits salt
}

if (CRYPT_EXT_DES == 1)
{
    echo "Extended DES: " . crypt("1234", "_J9..rasm"); // 9 digits salt
}

if (CRYPT_MD5 == 1)
{
    echo "MD5: " . crypt("1234", "$1$rasmusle$"); // 12 digits salt starting with $1$
}

if (CRYPT_BLOWFISH == 1)
{
    echo "Blowfish: " . crypt("1234", "$2a$07$usesomesillystringforsalt$"); // 22 character salt starting with $2$ | $2a$ | $2x$ | $2y$  
}

if (CRYPT_SHA256 == 1)
{
    echo "SHA-256: " . crypt("1234", "$5$rounds=5000$usesomesillystringforsalt$"); // 16 character salt starting with $5$ and number
}

if (CRYPT_SHA512 == 1)
{
    echo "SHA-512: " . crypt("1234", "$6$rounds=5000$usesomesillystringforsalt$"); // 16 character salt starting with $6$ and number
}

/*
htmlspecialchars
string = htmlspecialchars(string, style)
http://php.net/manual/en/function.htmlspecialchars.php
& : &
" : "
' : '
< : <
> : >

- flags 
ENT_COMPAT
ENT_QUOTES
ENT_NOQUOTES
ENT_IGNORE
ENT_SUBTITLE
ENT_DISALLOWED
ENT_HTML401
ENT_XML1
ENT_XHTML
ENT_HTML5

- encoding
ISO-8859-1
ISO-8859-5
ISO-8859-15
UTF-8
cp866
cp1251
KOI8-R
BIG5
GB2312
BIG5-HKSCS
Shift-JIS
EUC-JP
MacRoman
"
*/
$html = htmlspecialchars("Test", ENT_QUOTES);
echo $html; // <a href='test'>Test</a>

/*
htmlentities
string = htmlentities(string, flags, encoding)
http://php.net/manual/en/function.htmlentities.php
*/
$str = "\x8F!!!";
echo htmlentities($str, ENT_QUOTES, "UTF-8"); //
echo htmlentities($str, ENT_QUOTES | ENT_IGNORE, "UTF-8"); // !!!

/*
number_format
string = number_format(float, int, string, string)
http://php.net/manual/en/function.number-format.php
*/
$number = 1234.5678;
echo number_format($number); // 1,235
echo number_format($number, 2); // 1,234.57
echo number_format($number, 2, " point ", " and "); // 1 and 234 point 57
echo number_format($number, 2, ".", ""); // 1234.57

2014년 12월 9일 화요일

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
echo date("M", $maketime); // month 3 letters, Jan
echo date("m", $maketime); // month 2 digits, 01
echo date("n", $maketime); // month 1 digits, 1
echo date("t", $maketime); // last day of month
// Day
echo date("d", $maketime); // day 2 digits, 01
echo date("j", $maketime); // day 1 digits, 1
echo date("l", $maketime); // day full text, Sunday
echo date("D", $maketime); // day 3 letters, Sun
echo date("w", $maketime); // day representation, 0~6
echo date("S", $maketime); // day 2 letters, nd
echo date("z", $maketime); // day of the year, 0~365
// Time
echo date("g", $maketime); // time 1 digits, 1~12
echo date("h", $maketime); // time 2 digits, 01~12
echo date("G", $maketime); // time 1 digits, 1~24
echo date("H", $maketime); // time 2 digits, 01~24
echo date("a", $maketime); // am, pm
echo date("A", $maketime); // AM, PM
echo date("i", $maketime); // minute 2 digits, 00~59
echo date("s", $maketime); // second 2 digits, 00~59
// Date
echo date("c", $maketime); // ISO 8601, 1999-12-31 T10:10:30+09:00
echo date("r", $maketime); // RFC 2822, Sat 10 Nov 2000 10:10:30+12:00
echo date("U", $maketime); // TimeStamp

/*
getdate
array = getdate(int timestamp)
http://php.net/manual/en/function.getdate.php
*/
$array_time = getdate(time());
foreach($array_time as $key=>$value)
{
 echo $key . ":" . $value . "
"; } echo $array_time["0"]; echo $array_time["month"]; echo $array_time["weekday"]; echo $array_time["yday"]; echo $array_time["year"]; echo $array_time["mon"]; echo $array_time["wday"]; echo $array_time["mday"]; echo $array_time["hours"]; echo $array_time["minutes"]; echo $array_time["seconds"]; /* microtime mixed = microtime(bool get_as_float) http://php.net/manual/en/function.microtime.php */ echo microtime(FALSE); echo microtime(TRUE);

2014년 12월 8일 월요일

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 < 1";
}

// WHILE
while($i < 10)
{
 echo $i;
 $i++;
}

// DO WHILE
do
{
 echo $i;
 $i--;
}
while($i > 0);

// FOR
for($i=0; $i<10; $i++)
{
 echo $i;
}

// BREAK
while($i > 0)
{
 if ($i == 5)
 {
  echo "Break! \$i = " . $i;
  break;
 }
 echo $i;
 $i--;
}

// CONTINUE
for($i=0; $i<10; $i++)
{
 if($i%2==0)
 {
  echo " even ";
  continue;
 }
 echo $i; //odd
}

// SWITCH
switch($i%2)
{
 case(0) : 
 echo "\$i is even.";
 break;

 case(1) :
 echo "\$i is odd.";
 break;

 default:
 echo "\$i is not Number.";
}

// FOREACH
$abc = array("a"=>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";

2014년 12월 6일 토요일

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";
}

// FALSE
if ($a > $b)
{
 echo "TRUE";
}
else
{
 echo "FALSE";
}

// TRUE
if ($a <= $b)
{
 echo "TRUE";
}
else
{
 echo "FALSE";
}

// FALSE
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;

PHP 수치 연산자


/*
+ 더하기
- 빼기
* 곱하기
/ 나누기
% 나머지
*/

$a = 10;
$b = 4;

function calc($a,$b,$x)
{
// if ($x=="plus") { return $a + $b; }
 switch($x)
 {
  case "plus":
  return $a + $b;
  break;
  
  case "minus":
  return $a - $b;
  break;
 
  case "times":
  return $a * $b;
  break;

  case "divides":
  return $a / $b;
  break;

  case "leaves":
  return $a % $b;
  break;
 }
}
echo calc($a,$b,"plus");
echo calc($a,$b,"minus");
echo calc($a,$b,"times");
echo calc($a,$b,"divides");
echo calc($a,$b,"leaves");

유튜브 embed 태그

이제 유튜브에서 iframe 밖에 지원을 안하기 때문에...embed 태그를 정리
embed 는 PC 에서만 재생가능, 모바일에서는 iframe 태그로 해야한다.


<embed width = "512"
       height = "384"
       src = "http://www.youtube.com/v/주소"
       type = "application/x-shockwave-flash"
       allowscriptaccess = "always"
       allowfullscreen = "true">
</embed>

옵션

- 기본 360, 240-360-480-720-1080
&vq=light
&vq=medium
&vq=large
&vq=hd720
&vq=hd1080

- 자동재생
&vq=&autoplay=1

- 반복재생
?version=2&loop=1

- 시작지점,끝지점
&start=30
&end=300

- 추천동영상 표시
&rel=1


<embed width = "512" 
       height = "384" 
       src = "http://www.youtube.com/v/주소?version=2&loop=1&vq=hd720&autoplay=1&start=30&end=60&rel=0"
       type = "application/x-shockwave-flash" 
       allowscriptaccess = "always" 
       allowfullscreen = "true">
</embed>

<iframe width = "512" 
        height = "384" 
        src = "http://www.youtube.com/embed/주소?vq=large&autoplay=0&start=12&rel=1" 
        frameborder = "0" 
        allowfullscreen>
</iframe>

PHP 상수와 예약상수 정리


// 특징 = $ 없음, 보통 대문자로 표기

// 상수정의
define("A", 1.9);
echo A;

// 마법상수
echo __LINE__;
echo __FILE__;
echo __FUNCTION__;
echo __CLASS__;
echo __METHOD__;

// 예약상수
// http://kr.php.net/manual/kr/reserved.constants.php
echo PHP_VERSION;
echo PHP_MAJOR_VERSION;
echo PHP_MINOR_VERSION;
echo PHP_RELEASE_VERSION;
echo PHP_VERSION_ID;
echo PHP_DEBUG;
echo PHP_MAXPATHLEN;
echo PHP_OS;
echo PHP_SAPI;
echo PHP_EOL;
echo PHP_INT_MAX;
echo PHP_INT_SIZE;
echo DEFAULT_INCLUDE_PATH;
echo PEAR_INSTALL_DIR;
echo PEAR_EXTENSION_DIR;
echo PHP_EXTENSION_DIR;
echo PHP_PREFIX;
echo PHP_BINDIR;
echo PHP_LIBDIR;
echo PHP_DATADIR;
echo PHP_SYSCONFDIR;
echo PHP_LOCALSTATEDIR;
echo PHP_CONFIG_FILE_PATH;
echo PHP_CONFIG_FILE_SCAN_DIR;
echo PHP_SHLIB_SUFFIX;
echo PHP_OUTPUT_HANDLER_START;

PHP 예약변수 정리

http://kr.php.net/manual/kr/reserved.variables.php

// 예약변수
// PHP4 에서는 $_HTTP_GET_VARS 를 썼지만 PHP5 에서는 $_GET 으로 쓴다.
// php.ini 의 register_long_arrays = ON 으로 하면 PHP4 처럼 쓸 수 있다.
/*
PHP5 = PHP4
$_SERVER = $_HTTP_SERVER_VARS
$_GET = $_HTTP_GET_VARS
$_POST = $_HTTP_POST_VARS
$_COOKIE = $_HTTP_COOKIE_VARS
$_REQUEST
$_FILES = $_HTTP_POST_FILES
$_SESSION = $_HTTP_SESSION_VARS
$_ENV = $_HTTP_ENV_VARS
$GLOBALS
*/

// 1. $_SERVER
phpinfo(INFO_VARIABLES);
// 사용방법
echo $_SERVER["REMOTE_ADDR"];
echo $_SERVER["SCRIPT_NAME"];
echo $_SERVER["PHP_AUTH_USER"];
echo $_SERVER["PHP_AUTH_PW"];

// 2. $_GET
// 보내는 폼 a.php
// 받는 폼 b.php echo "\$_GET : " . $_GET["email"]; // 3. $_POST // 보내는 폼 a.php
// 받는 폼 b.php echo "\$_POST : " . $_POST["email"]; // 4. $_COOKIE // 5. $_REQUEST // 보내는 폼 a.php
//받는 폼 b.php echo "\$_REQUEST : " . $_REQUEST["email"]; // 6. $_FILES // 7. $_SESSION // 8. $_ENV phpinfo(INFO_ENVIRONMENT); // 9. $_GLOBALS

2014년 12월 4일 목요일

PHP 전역/지역변수,정적변수,가변변수



// 전역변수
$a = 1;
$b = 2;
function global_var()
{
 global $a;
 echo "\$a value is {$a}";
}
global_var();
unset($a);
unset($b);

// 지역변수
$a = 1;
$b = 2;
function local_var()
{
 $a = 2;
 echo "\$a value is {$a}";
}
local_var();
unset($a);
unset($b);

// global 키워드 사용
$a = 1;
$b = 2;
function sum1()
{
 global $a,$b;
 $b = $a + $b;
}
sum1();
echo "\$b value is {$b}";
unset($a);
unset($b);

// $GLOBALS 연관배열 사용
$a = 1;
$b = 2;
function sum2()
{
 $GLOBALS["b"] = $GLOBALS["a"] + $GLOBALS["b"];
}
sum2();
echo "\$b value is {$b}";
unset($a);
unset($b);

// 정적변수
function static_var()
{
 static $a = 10;
 echo "\$a value is {$a}";
 $a = $a + 1;
}
static_var();
static_var();
static_var();
echo "\$a value is {$a}";
unset($a);

// 가변변수
$a = "NEW";
${$a} = "OVERLOAD";
echo "a = " . $a;
echo "a = " . ${$a};
echo "a = " . $NEW;

PHP 배열 정리

// 1. a배열
$a[0] = "a";
$a[1] = "b";
$a[2] = "c";
echo $a[0] . $a[1] . $a[2];
unset($a);

// 2. 배열의 키와 값
$a["a"] = "A";
$a["b"] = "B";
$a["c"] = "C";
echo $a["a"] . $a["b"] . $a["c"];
unset($a);

// 3. 배열의 생성
$a = array(0=>"a",1=>"b",2=>"c");
echo $a[0] . $a[1] . $a[2];
unset($a);

$a = array("a"=>"A","b"=>"B","c"=>"C",);
echo $a["a"] . $a["b"] . $a["c"];
unset($a);

$a = array("a","b","c");
echo $a[0] . $a[1] . $a[2];
unset($a);

$a = array("a","b"=>"B","c"=>3);
echo $a["a"] . $a["b"] . $a["c"];
unset($a);

$a[] = "a";
$a[] = "b";
$a[] = "c";
echo $a[0] . $a[1] . $a[2];
unset($a);

// 4. 다차원 배열
$a = array(
  array("a"=>"A","b"=>"B"),
  array("A"=>"a","B"=>"b")
);
echo  $a[0]["b"] . $a[1]["B"];
unset($a);

$a[0]["a"] = "A";
$a[0]["b"] = "B";
$a[0]["c"] = "C";
$a[1]["a"] = "a";
$a[1]["b"] = "b";
$a[1]["c"] = "c";
echo $a[0]["c"] . $a[1]["c"];
unset($a);

$a = array(
 "A"=>array("a"=>"A","b"=>"B","c"=>"C"),
 "B"=>array("a"=>"A","b"=>"B","c"=>"C"),
 "C"=>array("a"=>"A","b"=>"B","c"=>"C")
);
echo $a["A"]["a"] . $a["B"]["a"] . $a["C"]["b"];
unset($a);

플러터 단축키

1. 위젯 감싸기/벗기기 비주얼 스튜디오 :   Cmd + . 안드로이드 스튜디오 : Alt + Enter 2. 코드 정렬 비주얼 스튜디오 : Ctrl + S 안드로이드 스튜디오 : Ctlr + Alt + L 3. StatelessWidget ->...