Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHP 프로그래밍. Let ’ s start test <? $string=“test”; $num=35; $float=45.14; echo $string ; echo " "; echo $num; echo " "; echo $float; echo " "; ?>

Similar presentations


Presentation on theme: "PHP 프로그래밍. Let ’ s start test <? $string=“test”; $num=35; $float=45.14; echo $string ; echo " "; echo $num; echo " "; echo $float; echo " "; ?>"— Presentation transcript:

1 PHP 프로그래밍

2 Let ’ s start test <? $string=“test”; $num=35; $float=45.14; echo $string ; echo " "; echo $num; echo " "; echo $float; echo " "; ?>

3 Basics PHP 코드의 시작과 끝 :

4 Basics Function – function fname (parm,..) { … } e.g.) function add($a,$b) { $value = $a+$b; return ($value); } $v = add(30,5);

5 functions <? function test($args) { $args += 10; } $realargs = 10; test($realargs); echo (“$realargs”); ?> => Results? 10 (call by value)

6 functions function makecoffee($type = “ cappucino ” ) { return $type; } echo makecoffee(); echo makecoffee( “ espresso ” );

7 Basics Function scope e.g.) $data = “test”; function aaa() { $data = “new”; echo $data; } echo $data;

8 Identifier, Comments 영문자, 밑줄, $ 기호로 시작 내장함수는 대소문자 구별하지 않음 –print = Print comments: /*, */, //, # 자료형 –Integer, Floating-point number, String, array, object – 특수문자 :\n,\r,\t, \\,\$, \ ” –string 사용법 : “ ”, ‘ ’

9 변수 : 전역변수, 지역변수 <? $a = 1; function test() { echo $a; } test(); ?> <? $a = 1; function test() { global $a; echo $a; } test(); ?>

10 Static Variable function Test() { static $a=0; echo $a; $a++; }

11 Variable type No specific type declaration required. Type casting –$foo=10; –$bar=(double) $foo; 관련함수 –gettype(), is_long(). Is_string(), is_array(), is_object(), …

12 변수타입 변환 문자열이 숫자 값일 때 : –. e E 는 double, 아니면 integer –$foo=1+”10.5”; // double(11.5) –$foo=1+”-1.3e3”;// double (-1299) –$foo=1+”bob-1.3e3”;//1 –$foo=1+”bob3”;//1 –$foo=1+”10 small pigs”;// 11 –$foo=“10.0 pigs”+1.0 ;// double (11.0)

13 변수 : 변수 받아오기 ID : <? $userid = $_POST[“userid"]; echo $userid; ?> 다른 Html 문서 test.php

14 Constant 예 ) <? define(“CONSTANT”, “Hello World”); echo(CONSTANT); ?> Pre-defined constants –_FILE_: 자신파일이름 –_LINE_: 현재 파일의 라인 위치 –PHP_VERSION, PHP_OS –TRUE, FALSE –E_ERROR, E_WARNING, E_PARSE, E_NOTICE

15 Array $a[0]= “ abc ” ; $b[ “ foo ” ]=13; $a[1][0]=$f; $a[ “ foo ” ][1]=$f;

16 Array Initialization $a = array ( “color”=>”red”, “taste”=>”sweet”, 3=>4); $a = array ( “apple” => array ( “color” => “red”, “taste”=>”sweet”), “orange”=> array ( … ) );

17 수식과 연산자 $count +=count; 산술 연산자 : –$a+$b; $a-$b; $a*$b; $a/$b; $a%$b; 문자열 –$b= “ hello ”. ” world ” ; 비트연산자 –$a&$b; $a|$b;$a^$b; ~$a; $a > $b; 논리연산자 –$a and $b; $a or $b; $a or $b; !$a; $a && $b; $a || $b; 비교연산자 –$a == $b; $a !=$b; $a < $b; $a <= $b;

18 if if (expr) {statement;} if (expr1) {statement1;} elseif (expr2) else { statement2;} a=5; b=4;

19 while while (expr) { statement1;} while (expr): statement1; endwhile <? $x=1; while ($x <= 100): $sum += $x; $x +=1; endwhile; ?>

20 for for (expr1;expr2;expr3) { statement1; … } for (expr1; expr2; expr3): statement1; endfor;

21 Class & Object <? class Cart { var $items; function add_item ($artnr, $num) { $this->items[$artnr] +=$num; } $cart = new Cart; $cart->add_item(“10”,1); ?>

22 문자열 처리 함수 print: 데이타출력 –print (“$var: this is test”); sprintf,printf: 문자열의 포맷정의 –$return=sprintf(“test: %d”, $test); –$var1= sprintf(“%c”, $var[1]);

23 PHP: MySQL DB 연동 <? $connect = mysql_connect( $host, $user, $password ); mysql_select_db( $dbname, $connect ); $query = “select name, age from ………;”; $result = mysql_query( $query, $connect ); while( $row = mysql_fetch_object( $result ) ) { echo $row->name; echo $row->age; } mysql_free_result( $result ); ?>


Download ppt "PHP 프로그래밍. Let ’ s start test <? $string=“test”; $num=35; $float=45.14; echo $string ; echo " "; echo $num; echo " "; echo $float; echo " "; ?>"

Similar presentations


Ads by Google