In the PHP learning process encountered in the small examples to do with a simple enumeration and explanation, I hope to have just contact with PHP white have a certain auxiliary role.
1. Enter m,n with the keyboard, calculate the value of M to N, and output the form of m+........+n=
Design keyboard input will not say, after the design, create a new page for the output, the code is as follows
<?
$m =$_post["M"];
$n =$_post["n"];
$sum = 0;
for ($i = $m; $i <= $n; $i + +)
{
if ($i < $n)
{
Echo$i. " +";
}
Else
{
Echo$i. " =";
}
$sum + = $i;
}
Echo$sum;
?>
2. Determine if the file extension meets the requirements.
<?
$pic =$_post["pic"];
$arr =explode (".", $pic);
$a = $arr [count ($arr)-1];
$b =array ("JPG", "BMP", "GIF");
if (In_array ($a, $b))
{
echo "OK";
}
Else
{
echo "fail";
}
?>
3.strlen () function traversal string
<?
$n = "Power";
for ($i =0; $i <strlen ($n); $i + +)
{
echo$n[$i]. " <br> ";
}
?>
The output is as follows:
P
O
W
E
R
However, there are many ways to traverse a string, depending on how the program executes, or depending on the situation.
The above is our learning PHP programming will encounter the small program, whether it is to participate in PHP training or self-study, should have just started to form a complete set of knowledge system, so for the future of PHP program learning to have a greater interest, in the distance from the PHP development engineer will be more and more close to the road.
A tutorial on the PHP base code case