web programming - kocwcontents.kocw.net/kocw/document/2014/wonkwang/leehyun... · 2016. 9. 9. ·...
TRANSCRIPT
-
WONKWANG UNIVERSITY
Web Programming
FUNCTION
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL 2
CONTENTS
User defined function
String related function
Data and time related functions
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL 3
User defined function
A function will be executed by a call to the function.
like procedure, subroutine
purpose : modularization and structuralization
format
Function function_name ( parameter-list ) {
statements;
return return_value;
}
ex
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL 4
User defined function(2)
Function including parameters
A parameter is just like a variable
Parameters are specified after the function name, inside the parentheses
Distinguishing parameters with “,”
ex
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL 5
User defined function(3)
Passing parameters with default value
parameter passing by reference
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL 6
User defined function(4)
Function with return value
Return result value using keyword return
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL 7
User defined function(5)
Conditional function :
In the previous version(PHP-3), before being referenced function, it must be pre-defined
No constraints but conditional definition of function
example of function inside conditional statements
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
User defined function(6)
Function definition inside function
8
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
User defined function(7)
ex (with one parameter)
9
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
User defined function(8)
Ex with return value
10
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
User defined function(9)
Ex for ftp connection
11
format : ftp_connect(host,port,timeout)
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
String related function
Input between the single quotes, double quotes
1. addslashes( ) : function adding backslash ‘ \’ to in front of the possible
conflicts special character in such as DB query, quoted string
Special characters 4: ‘ ‘, “ “, \, NUL (Null byte)
ex: Bean’s Magic
Search script: select * from book where title = ‘Bean’s Magic’
Error occurred (∵special character): ∴ ‘Bean\’s Magic’
12
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
String related function(2)
2. bin2hex() : convert binary data into hexadecimal representation
4 bits per hexadecimal characters ( ‘0’ ~ ‘f’ )
13
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
String related function(3)
3. chop() : : remove the specified character or whitespaces of the end of a
string
format : string chop ( string str [, string charlist ] )
4. chr() : change ASCII decimal number into a character of string
format : string chr ( int ascii )
14
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
String related function(4)
5. crypt() : return an encrypted string using the standard Unix DES-based
encryption algorithm, or a variety of algorithms available on the system
format: string crypt ( string str [, string salt ])
15
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
String related function(5)
6. echo : used when more than one string to output
format : void echo ( string arg1 [, string arg n …] )
16
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
String related function(6)
7. explode( ) : function for storing string in an array form after separating
the string using a specified delimiter
format : array explode ( string separator, string string [, int limit ] )
17
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
String related function(7) -X
8.htmlentities() : function for representing HTML entity character, special character, in a string in web browser
format: string htmlentities ( string string [, int quote_style [, string charset ] ] )
quote_style :
charset: character set to converse (default:ISO-8859-1)
18
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
String related function(8)-X
9.htmlspecialchars(): if HTML entity character in a string, convert like following
format : string htmlspecialchars ( string string [, int qquote_style [, string charset]])
HTML entity character
문자 HTML Entities
& &
“ " ( ENT_NOQUOTES를 지정하지 않았을 때 )
‘ ' ( ENT_QUOTES를 지정했을 때만)
< <
> >
19
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
String related function(9)
10. Implode() : convert each element in an array using delimiter into a string
the opposite of explode()
format: string implode ( string glue, array piece )
ex
20
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
String related function(10)
11. ltrim () : used to remove the spaces or a specified character at the beginning of the string
format : string ltrim ( string str [, string charlist ] )
characters to eliminate
“ “ (ASCII 32 (0x20)):
“\t” (ASCII 9 (0x09)):
“\n” (ASCII 10 (0x0A)):
“\r” (ASCII 13 (0x0D)):
“\0” (ASCII 0 (0x00)):
“\x0B” (ASCII 11 (0x0B)):
21
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
String related function(11)
12.nl2br () : convert strings including newline key into string including “
” stringformat: string nl2br ( string string )
ex
22
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
String related function(12)
13. parse_str( ) : process the value of QUERY_STRING format string and generate variable, substitute for the value.
extract the variable and value both, replace each
format : void parse_str ( string str [, array arr] )
ex
23
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
String related function(13)
14. print () : similar function of echo, used when printing string
format : int print ( string arg )
print - arg, always return 1.
24
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
String related function(14)
15. printf( ) : output a formatted string that begins with %
format : string printf ( string format [, mixed args ] )
Formal indicator
%c : dealing parameters in numeric and express character applicable ASCII
%d : decimal numeric
%s : string
ex
25
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
String related function(15)
16. strchr () : return that string after string that matches a specified string
format : string strchr ( string haystack, string needle )
ex
26
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
String related function(16)
17. strcmp () : : return integer value after comparing 2 strings
format : int strcmp ( string str1, string str2 )
str1 is less than str2 : return -1
str1 is greater than str2 : return 1
Str1 is same as str2 : return 0
Caution : case sensitive
27
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
String related function(17)
18. strip_tags () : return a string after eliminating tags in strings containing PHP or HTML tags
19. strlen() : return an integer value of the string length
format : int strlen ( string str )
28
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
String related function(18)
20. strncmp () : compare two strings from the beginning to the certain length of the strings
forma: int strncmp ( string str1, string str2, int len )
21. strpos () : return the first location of specific strings appeared in the target string, the first location returned
29
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
String related function(19)
22. substr() : return a new string from the string beginning at a specified position to the end of a apecified length
format : string substr ( string string, int start [, int length ] )
30
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
String related function(20)
23. trim () : remove whitespace characters at the beginning and end of the string
String trim ( string str )
31
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
Data and Time related function
getdate() : return the date and time as a specified form of an array
form: array getdate( [ int timestamp ] )
32
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
Data and Time related function(2)
Date() : formatted date and time string returned
format: string date ( string format [, int timestamp ] )
Directive:
33
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL
Data and Time related function(3)
Time() : function that returns the current time in timestamp format
format: int time ( void )
Checkdate() : function to determine whether a given date is valid
format : bool checkdate( int month, int day, int year )
34
-
WONKWANG UNIVERSITY Division of Information and e-Commerce - HCL 35
The End
User defined function
String related function
Data and time related functions