php5 study #1 100223 sparcs 구성모. 공부하기전에 xming xlaunch windows 용 xserver...

Post on 18-Jan-2018

239 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

PHP  스크립트 언어  PHP1 : Personal Home Page Tools 1.0  PHP2 : HTML 파싱  PHP3 : PHP : Hypertext Preprocessor  PHP4  PHP5 : 객체지향

TRANSCRIPT

PHP5 STUDY #1PHP5 STUDY #1

100223100223SPARCS SPARCS 구성모구성모

공부하기전에공부하기전에

XmingXming

XlaunchXlaunch WindowsWindows 용 용 Xserver Xserver 프리웨어프리웨어

PHPPHP 스크립트 언어스크립트 언어 PHP1 : Personal Home Page Tools 1.0PHP1 : Personal Home Page Tools 1.0 PHP2 : HTML PHP2 : HTML 파싱파싱 PHP3 : PHP : Hypertext PreprocessorPHP3 : PHP : Hypertext Preprocessor PHP4PHP4 PHP5 : PHP5 : 객체지향객체지향

PHPPHP 와 비슷한 언어와 비슷한 언어 C, Perl, ASPC, Perl, ASP JSPJSP 프레임워크 프레임워크 : Django, Rails: Django, Rails

간단한 간단한 PHP PHP 예제예제<!-- ~/public_html/hello.php --><!-- ~/public_html/hello.php --><html><html>

<head></head><head></head><body><body><?php<?php

echoecho?>?></body></body>

</html></html>

““ 현재시각” 현재시각” . date(‘h:i:s’);. date(‘h:i:s’);““Hello, world!”;Hello, world!”;

PHP PHP 실행 구조실행 구조클라이언트

웹서버

PHP 엔진확장 모듈

DB 외부라이브러리

출력출력<?<?

echo (“hi 1”);echo (“hi 1”);echo “hi 2”;echo “hi 2”;print (“hi 3”);print (“hi 3”);print “hi 4”;print “hi 4”;echo(print “hi 5”);echo(print “hi 5”);

?>?><?=“hi 6”?><?=“hi 6”?>

주석주석 한줄주석한줄주석

//// ##

여러줄 주석여러줄 주석 /* ~ *//* ~ */

변수형변수형 (Type)(Type) IntegerInteger FloatFloat StringString BooleanBoolean NULLNULL ArrayArray ObjectObject

StringString HERE docs : escape characterHERE docs : escape character 를 무시함를 무시함<?php<?php$str = <<<EOD$str = <<<EODExample of string /nExample of string /nSpanning multiple lines /t $srtSpanning multiple lines /t $srtUsing heredox syntax.Using heredox syntax.EOD;EOD;?>?>

BooleanBoolean TRUE, FALSETRUE, FALSE FalseFalse 가 되는 값들가 되는 값들

Integer 0Integer 0 Float 0.0Float 0.0 String “”, “0”String “”, “0” 아무런 요소도 가지지 않은 배열아무런 요소도 가지지 않은 배열 아무 멤버 변수도 가지지 않은 객체아무 멤버 변수도 가지지 않은 객체 NULLNULL

Type JugglingType Juggling

<?<?print “4” + 2;print “4” + 2;print “4” . 2;print “4” . 2;$a = 3;$a = 3;print (real)$a;print (real)$a;print “5 < $a”;print “5 < $a”;?>?>

변수변수 copy by valuecopy by value 참조참조 (&)(&) 상수상수

>define(‘RED’, “BLUE”);>define(‘RED’, “BLUE”);>print RED;>print RED;

변수변수<?php<?php

$a = “hello”;$a = “hello”;$$a = “world”;$$a = “world”;print $$a;print $$a;print “$a $hello”;print “$a $hello”;print “$$a”print “$$a”print “{$$a}”print “{$$a}”

?>?>

연산자연산자 .= , AND , OR , XOR , === , ? :.= , AND , OR , XOR , === , ? :

변수 관련 함수변수 관련 함수 is_int()is_int() is_null()is_null() is_finite()is_finite() settype()settype() unset()unset()

ifif 문문if()if(){{}}elseif()elseif(){{}}elseelse{{}}

if():if():

elseif():elseif():

else():else():

endif;endif;

switchswitch 문문switch()switch(){{

case value1 :case value1 :

default :default :

}}

반복문반복문

whilewhile do-whiledo-while breakbreak continuecontinue for(for( 초기화초기화 , , 조건조건 , , 증가식증가식 )) foreachforeach endforendfor

exitexit

<?php<?php$filename = “./hello.php”;$filename = “./hello.php”;$file = fopen($filename, ‘r’)$file = fopen($filename, ‘r’)

or exit(“unable to open file $filename”);or exit(“unable to open file $filename”);echo “<br>after file open”;echo “<br>after file open”;?>?>

die, returndie, return

배열배열<?php<?php$cs[“CS300”] = “Algorithm”;$cs[“CS300”] = “Algorithm”;$cs[“CS320”} = “PL”;$cs[“CS320”} = “PL”;

print $cs[“CS320”];print $cs[“CS320”];?>?>

배열배열<?<?$cs[] = “Algorithm”;$cs[] = “Algorithm”;$cs[] = “PL”;$cs[] = “PL”;

print $cs[1];print $cs[1];print $cs;print $cs;print_r($cs);print_r($cs);

foreachforeach

foreach($cs as $value){foreach($cs as $value){print $value;print $value;

}}

foreach($cs as $key => $value){foreach($cs as $key => $value){print $key.”:”.$value;print $key.”:”.$value;

}}

배열배열 초기화초기화

$cs = array(3=>”Algorithm”, “PL”);$cs = array(3=>”Algorithm”, “PL”);

다중 배열다중 배열 +(+( 통합연산자통합연산자 ))

배열 관련 함수배열 관련 함수 array_flip()array_flip() array_keys()array_keys() array_merge()array_merge() array_push()array_push() array_rand()array_rand() array_reverse()array_reverse() array_slice();array_slice(); array_sum();array_sum(); array_each();array_each();

함수함수 function name(){}function name(){} call by valuecall by value

가변함수가변함수<?<?function printbold($str){function printbold($str){

print(“<b>$str</b>”);print(“<b>$str</b>”);}}$myf = “printbold”;$myf = “printbold”;print $myf(“SPARCS”);print $myf(“SPARCS”);?>?>

고급고급 클래스클래스 , , 파일파일 데이터베이스데이터베이스 네트워크네트워크 디자인디자인

마치며마치며

top related