A tutorial on the PHP base code case

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.