Saturday, December 13, 2014

윈도우 시간 동기화 오류

윈도우 업데이트 이후

컴퓨터 시계 시간이 
자꾸만 엉뚱하게 나와
찾아보니

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

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

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

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

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



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

Friday, December 12, 2014

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

Tuesday, December 9, 2014

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);