php variable length argument
Post on 02-Jun-2018
221 Views
Preview:
TRANSCRIPT
-
8/10/2019 PHP Variable Length Argument
1/71
Variable Length Argument
Function
Haresh Khachariya
(Lecturer)
Shree M & N Virani Science College ,
Rajkot
-
8/10/2019 PHP Variable Length Argument
2/71
func_num_args
Returns the number of arguments passed into the
current user-defined function.
Syntax:
2
int func_num_args ( void)
-
8/10/2019 PHP Variable Length Argument
3/71
Example
3
-
8/10/2019 PHP Variable Length Argument
4/71
func_get_arg
Returns the argument which is at the arg_num'th
offset into a user-defined function's argument list.
Function arguments are counted starting fromzero.
Syntax:
4
mixed func_get_arg ( int arg_num)
-
8/10/2019 PHP Variable Length Argument
5/71
5
-
8/10/2019 PHP Variable Length Argument
6/71
func_get_args
It creates and returns an array which contains
values of all arguments provided in the function
call operation.
Syntax
6
array func_get_args ( void)
-
8/10/2019 PHP Variable Length Argument
7/71
function fnum_args()
{$num_args = func_num_args();
echo "Number of arguments: $num_args
";$arg_list = func_get_args();
for ($i = 0; $i < $num_args; $i++)
{echo "Argument $i is: " . $arg_list[$i] . "
\n";}
} fnum_args(1, 2, 3); ?> 7
-
8/10/2019 PHP Variable Length Argument
8/71
Variable Function
8
-
8/10/2019 PHP Variable Length Argument
9/71
gettype()
The gettype() function return the type of a
variable.
Syntax:
9
gettype(var_name)
-
8/10/2019 PHP Variable Length Argument
10/71
Example
10
-
8/10/2019 PHP Variable Length Argument
11/71
settype()
The settype() function is used to set the type of
a variable.
Return TRUE on success or FALSE on failure.
Syntax:
11
settype(var_name, var_type)
l
-
8/10/2019 PHP Variable Length Argument
12/71
Example $var1='98'; $var2='01'; $var3=10; $var4=true;
settype($var1, "integer"); settype($var2, "integer");
settype($var3, "string"); settype($var4, "null");
echo ($var1.'
'); echo ($var2.'
');echo ($var1+$var2.'
');echo gettype($var3)."
"; echo gettype($var4);?>
Output
98 1 99 string NULL 12
-
8/10/2019 PHP Variable Length Argument
13/71
isset ()
The isset () function is used to check whether a value
of variable is set or not.
The isset() function return false if testing variable
contains a NULL value or unset using unset()function and return true if testing variable contains
values or set.
Syntax:
13isset(variable1)
l
-
8/10/2019 PHP Variable Length Argument
14/71
Example
Output
bool(true) bool(false) bool(false)
14
-
8/10/2019 PHP Variable Length Argument
15/71
unset()
The unset() function destroys a given variableor unset the given variable.
Syntax:
15
unset (var1)
-
8/10/2019 PHP Variable Length Argument
16/71
Example
16
-
8/10/2019 PHP Variable Length Argument
17/71
strval()
The strval() is used to convert a value of avariable to a string.
Syntax:
17
strval(var_name)
-
8/10/2019 PHP Variable Length Argument
18/71
Example
18
-
8/10/2019 PHP Variable Length Argument
19/71
intval()
The intval() function is used to get the integervalue of a variable.
Syntax:
19
intval(var_name)
-
8/10/2019 PHP Variable Length Argument
20/71
Example
20
-
8/10/2019 PHP Variable Length Argument
21/71
floatval()
The floatval() function is used to convert a valueto a float.
Syntax:
21
floatval (var1)
-
8/10/2019 PHP Variable Length Argument
22/71
Example
22
-
8/10/2019 PHP Variable Length Argument
23/71
print_r()
The print_r() function is used to print value of
variable or array with returns keys and elements
information.
Syntax:
23
print_r(var_name, return_output)
-
8/10/2019 PHP Variable Length Argument
24/71
echo()
The echo() function outputs one or more strings.
Syntax:
24
echo(strings)
-
8/10/2019 PHP Variable Length Argument
25/71
Difference Between Echo And Print_r
echo is used to output and display single types
(strings, ints, etc).
echo is a statement.
echo is a raw language construct print_r is used to output and display the contents of an
array.
while print is a function.
print_r is functions with return values.
25
-
8/10/2019 PHP Variable Length Argument
26/71
File handling Function
26
-
8/10/2019 PHP Variable Length Argument
27/71
fopen()
The fopen() function is used to open files in PHP.
The first parameter of this function contains the
name of the file to be opened and the secondparameter specifies in which mode the file should
be opened.
If fopen is unable to open the file, it returns 0
(zero) otherwise it will return 1.
27
-
8/10/2019 PHP Variable Length Argument
28/71
Syntax and Example
var_name=fopen(file_name,file_open_mode)
-
8/10/2019 PHP Variable Length Argument
29/71
The file may be opened in one of the following modes
Modes Description
r Read only. Starts at the beginning of the filer+ Read/Write. Starts at the beginning of the file
w Write only. Opens and clears the contents of
file; or creates a new file if it doesn't exist
w+ Read/Write. Opens and clears the contents of
file; or creates a new file if it doesn't exist
a Append. Opens and writes to the end of the
file or creates a new file if it doesn't exist
a+ Read/Append. Preserves file content by
writing to the end of the file
x Write only. Creates a new file. ReturnsFALSE and an error if file already exists
x+ Read/Write. Creates a new file. Returns
FALSE and an error if file already exists
29
-
8/10/2019 PHP Variable Length Argument
30/71
fwrite()
The fwrite function allows data to be written to
any type of file and an open file.
The function will stop at the end of the file orwhen it reaches the specified length, whichever
comes first.
This function returns the number of bytes written
on success, or FALSE on failure.
30
-
8/10/2019 PHP Variable Length Argument
31/71
Syntax and Example
var_name =fwrite(file,string,length)
-
8/10/2019 PHP Variable Length Argument
32/71
fread()
The fread() reads from an open file.
The function will stop at the end of the file or
when it reaches the specified length, whichevercomes first.
fread() function returns the read string on success,or FALSE on failure.
32
-
8/10/2019 PHP Variable Length Argument
33/71
Syntax and Example
Syntax:
-
8/10/2019 PHP Variable Length Argument
34/71
fclose()
The fclose() function closes an open file.
fcose() function returns TRUE on success or
FALSE on failure.
34
-
8/10/2019 PHP Variable Length Argument
35/71
Syntax and Example
Syntax:
fclose(file)
-
8/10/2019 PHP Variable Length Argument
36/71
file_exists()
file_exists() function is used to check whether a
file or directory exists or not.
Return TRUE if the file or directory specifiedby file_name exists otherwise FALSE.
36
-
8/10/2019 PHP Variable Length Argument
37/71
Syntax and Example
Syntax:
37
var_name=file_exists (file_name)
i d bl
-
8/10/2019 PHP Variable Length Argument
38/71
is_readable
The is_readable() function is used to check whether
the specified file is readable or not.
TRUE if file_name exists and is readable, FALSE
otherwise.
38
d l
-
8/10/2019 PHP Variable Length Argument
39/71
Syntax and Example
is_readable(file_name)
39
bl ()
-
8/10/2019 PHP Variable Length Argument
40/71
is_writable()
The is_writable() function is used to check whether
the specified file is writeable.
TRUE if file_name exists and is writable.
40
S d E l
-
8/10/2019 PHP Variable Length Argument
41/71
Syntax and Example
is_writable(file_name)
41
f ()
-
8/10/2019 PHP Variable Length Argument
42/71
fgets()
The fgets() function is used to get line from file
pointer of an open file.
The fgets() function stops returning on a new line, atthe specified length, or at EOF, whichever comes
first.
This function returns FALSE on failure.
42
S d E l
-
8/10/2019 PHP Variable Length Argument
43/71
Syntax and Example
fgets(file_handler, byte_length)
43
Name Descriptionfile_handler When a file is successfully opened by fopen() or
fsockopen() it returns a resource ID, which isreferred as file handler or file pointer. The fgets()function uses this ID to return a series of bytes
from an open filebyte_length Specifies the number of bytes to read. Default
length is 1024.
-
8/10/2019 PHP Variable Length Argument
44/71
44
f t ()
-
8/10/2019 PHP Variable Length Argument
45/71
fgetc()
The fgetc() function reads a single character from a
open file pointed by file handler..
A string containing a single character and FALSE onEOF.
45
S t d E l
-
8/10/2019 PHP Variable Length Argument
46/71
Syntax and Example
fgetc(file_handler)
46
fil ()
-
8/10/2019 PHP Variable Length Argument
47/71
file()
The file() reads whole file into an array.
Each array element contains a line from the file, with
newline still attached.
47
S t d E l
-
8/10/2019 PHP Variable Length Argument
48/71
Syntax and Example
file(path,include_path,context)
48
fil t t t ()
-
8/10/2019 PHP Variable Length Argument
49/71
file_get_contents()
The file_get_contents() reads a whole file into a
string.
file_get_contents (file_name, include_path_name, context,
star_position, max_length)
49
-
8/10/2019 PHP Variable Length Argument
50/71
Parameter Description
path Required. Specifies the file to read
include_path Optional. Set this parameter to '1' if you want to search for
the file in the include_path (in php.ini) as well
context Optional. Specifies the context of the file handle. Context is a
set of options that can modify the behavior of a stream. Can
be skipped by using NULL.
start Optional. Specifies where in the file to start reading. Thisparameter was added in PHP 5.1
max_length Optional. Specifies how many bytes to read. This parameter
was added in PHP 5.1
50
E ample
-
8/10/2019 PHP Variable Length Argument
51/71
Example
51
file putcontents()
-
8/10/2019 PHP Variable Length Argument
52/71
file_putcontents()
The file_put_contents() function writes a string
to a file.
52
file_put_contents(file,data,mode,context)
Syntax and Example
-
8/10/2019 PHP Variable Length Argument
53/71
Syntax and Example
Parameter Description
file Required. Specifies the file to write to. If the file does notexist, this function will create one
data Required. The data to write to the file. Can be a string, an array or adata stream
mode Optional. Specifies how to open/write to the file. Possible values:
FILE_USE_INCLUDE_PATHFILE_APPENDLOCK_EX
context Optional. Specifies the context of the file handle. Context is a set ofoptions that can modify the behavior of a stream.
53
-
8/10/2019 PHP Variable Length Argument
54/71
54
ftell()
-
8/10/2019 PHP Variable Length Argument
55/71
ftell()
The ftell() function is used to fetch the current
position of the file pointer of an open file.
55
ftell(file_handler)
Example
-
8/10/2019 PHP Variable Length Argument
56/71
Example
56
fseek()
-
8/10/2019 PHP Variable Length Argument
57/71
fseek()
The fseek() function is used to move the file pointer
in an open file.
This function moves the file pointer from its current
position to a new position, forward or backward,
specified by the number of bytes.
This function returns 0 on success, or -1 on failure.
57
Syntax and Example
-
8/10/2019 PHP Variable Length Argument
58/71
Syntax and Example
fseek(file,offset,whence)
58
Parameter Description
file Required. Specifies the open file to seek in
offset The the number of bytes to move the file pointer.
whence Optional. (added in PHP 4). Possible values:
SEEK_SET - Set position equal to offset.DefaultSEEK_CUR - Set position to current locationplus offsetSEEK_END - Set position to EOF plus offset (tomove to a position before EOF, the offset mustbe a negative value)
-
8/10/2019 PHP Variable Length Argument
59/71
Atmiya College Rajkot Comp. Dept.
0
iya College Rajkot Comp. Dept.
59
rewind()
-
8/10/2019 PHP Variable Length Argument
60/71
rewind()
The rewind() function is used to set the file pointer to
the beginning of the file.
This function returns TRUE on success, or FALSE on
failure.
60
Syntax and Example
-
8/10/2019 PHP Variable Length Argument
61/71
Syntax and Example
rewind (file_handler)
61
copy()
-
8/10/2019 PHP Variable Length Argument
62/71
copy()
The copy() function copies a file from source to
destination.
This function returns TRUE on success and FALSE
on failure.
62
Syntax and Example
-
8/10/2019 PHP Variable Length Argument
63/71
Syntax and Example
copy(source, destination)
1 63
unlink()
-
8/10/2019 PHP Variable Length Argument
64/71
unlink()
The unlink() function deletes a file.
This function returns TRUE on success, or FALSE on
failure.
unlink(filename)
64
Example
-
8/10/2019 PHP Variable Length Argument
65/71
Example
65
rename()
-
8/10/2019 PHP Variable Length Argument
66/71
rename()
The rename() function renames directory or a
file.
rename(old_filename, new_filename, context)
66
move uploaded file()
-
8/10/2019 PHP Variable Length Argument
67/71
move_uploaded_file()
The move_uploaded_file() function moves an
uploaded file to a new location.
This function returns TRUE on success, or FALSE on
failure.
67
Syntax
-
8/10/2019 PHP Variable Length Argument
68/71
Syntax
move_uploaded_file(file,newloc)
68
Parameter Description
file Required. Specifies the file to be movednewloc Required. Specifies the new location for the file
Example
-
8/10/2019 PHP Variable Length Argument
69/71
Example
$target_path = "img/".$_FILES['image1']['name'];
if(move_uploaded_file($_FILES['image1']['tmp_name'],
$target_path))
{
echo "File is uploaded";
}
else
{ echo "File isnot uploaded"; }
?>69
-
8/10/2019 PHP Variable Length Argument
70/71
70
-
8/10/2019 PHP Variable Length Argument
71/71
Questions?
top related