PHP: introduction
Download
Report
Transcript PHP: introduction
PHP:
User-Defined and Built-in Functions
Speaker: Chin-Chang Chang
Date:2007.3.21
1
User-Defined Functions
function function_name (parameters)
{
entity;
}
function_name();
2
demo
hello();
function hello()
{
echo "Hello, world!";
}
http://stu.csie.ncnu.edu.tw/~beautidays.99/demo6.phps
3
$GLOBALS (1/2)
$temp = 6;
clear();
echo $temp;
function clear()
{
$temp = 0;
}
http://stu.csie.ncnu.edu.tw/~beautidays.99/demo7.p
hps
4
$GLOBALS (2/2)
$temp = 6;
clear();
echo $temp;
function clear()
{
$GLOBALS[ 'temp' ] = 0;
}
http://stu.csie.ncnu.edu.tw/~beautidays.99/demo8.p
hps
5
demo
hi(Joe, 18);
hi(May, 23);
function hi($x, $y)
{
echo $x . " is " . $y . " years old.<br>";
}
http://stu.csie.ncnu.edu.tw/~beautidays.99/demo9.p
hps
6
rand();
rand($min, $max);
$i = rand();
echo $i . "<br>";
$j = rand(1,1000);
echo $j;
http://stu.csie.ncnu.edu.tw/~beautidays.99/demo10.phps
7
getdate();
getdate();
Return an array
$today=getdate();
echo $today[year];
echo $today[mon];
echo $today[mday];
http://stu.csie.ncnu.edu.tw/~beautidays.99/date.php
s
8
strlen();
strlen($string);
$s=“Good Afternoon”;
$len=strlen($s);
echo $s;
echo “The length is ”.$len;
http://stu.csie.ncnu.edu.tw/~beautidays.99/strlength.phps
9
Reference
http://www.php.net/docs.php
http://member.ettoday.com/book/
10
HW3
http://solomon.ipv6.club.tw/Course/Database.952/hw3.html
Two URLs: one for source code and one for
execution.
11