int is_stringmixed var Description The is_string function returns true if var is a string and returns false otherwise.. isset Syntax int issetmixed var Description The isset functio
Trang 1int is_string(mixed var)
Description
The is_string() function returns true if var is a string and returns false otherwise
isset()
Syntax
int isset(mixed var)
Description
The isset() function returns true if var exists and returns false otherwise
$avar = 100;
echo isset($avar);//displays 1
print_r()
Syntax
void print_r(mixed expression);
Description
The print_r() function, which was added in PHP 4.0, displays human-readable information about the values of variables If expression is a string, integer, or
double, the value itself will be printed If expression is an array, the keys and
values will be displayed Similar notation is used for objects
$array1 = array (1,2,3);
print_r($array1);
//displays Array ( [0] => 1 [1] => 2 [2] => 3 )
settype()
Trang 2IT-SC book 191
Syntax
int settype(string var, string type)
Description
The settype() function sets the type of var to that of type Possible values of type
are "integer", "double", "string", "array", and "object" The return value is true if the type could be set, and false otherwise
strval()
Syntax
string strval(mixed var)
Description
The strval() function returns the string representation of var var must be a
scalar type and not an array or object
unset()
Syntax
int unset(mixed var)
Description
The unset() function destroys the specified variable and returns true
var_dump()
Syntax
void var_dump(mixed expression)
Description
Trang 3The var_dump() function, which was added in PHP 3.0.5 and PHP 4.0, displays structured information about an expression, including its type and value Arrays are processed recursively with values indented to show structure
$array1 = array (1,2,3);
var_dump($array1);
//displays array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }
Trang 4IT-SC book 193
Chapter 6 Protocol Extensions
On the Internet, there are lots of methods, called protocols, of moving files and data
around from place to place These protocols are what enable us to move files, send and receive email, download Web pages, manage networks, and much more
Within the PHP programming language are several sets of functions that provide the ability to use these protocols They are the focus of this chapter and are as follows:
• FTP
• HTTP
• IMAP, POP3, and NNTP
• LDAP
• SNMP
FTP
The File Transfer Protocol (FTP) is a standard Internet protocol that is used to exchange files Generally speaking, FTP commands are issued either on a command-line interface or through an application You can read the Request For Comments (RFC) on FTP at http://www.ietf.org/rfc/rfc0959.txt
Note
For those of you using PHP 3, this library of functions was not added until 3.0.13
ftp_cdup()
Syntax
int ftp_cdup(int ftp_stream)
Description
The ftp_cdup() function instructs the connection to change to the parent directory
of the current working directory in ftp_stream, which is the name handle of a previously opened stream using ftp_connect() If successful, 1 is returned If the function fails, 0 is returned
Trang 5The following short example moves up one directory on the system, whose connection is defined by $my_conn The result of the operation is stored in $status
If successful, this will contain 1; otherwise, it will contain an error message
$status = ftp_cdup($my_conn);
ftp_chdir()
Syntax
int ftp_chdir(int ftp_stream, string directory)
Description
The ftp_chdir() function changes the current working directory of ftp_stream, which is the name handle of a previously opened stream using ftp_connect(), to directory If successful, 1 is returned; otherwise 0 is returned on an error
ftp_connect()
Syntax
int ftp_connect(string host, int [port] )
Description
The ftp_connect() function opens an FTP connection to host when successful If the optional port is specified, the function attempts to open a connection to that specific port rather than to the default port 21 If the function fails, an error is returned
The following short example shows how you would connect to ftp.mcp.com and store the FTP stream reference in $my_conn The result of the operation is stored in
$status If successful, this will contain 1; otherwise, it will contain an error message
$status = ftp_connect('ftp.mcp.com');
ftp_delete()
Syntax