PHP ii., 1th part easy webzine Edit and send

Source: Internet
Author: User

As a language for building dynamic Web pages, PHP provides a simplified way to construct complex and powerful WEB-related programs. Erik the basics of PHP with a primitive, real-world website example. This series of articles is divided into two parts, the 1th part introduces the basic concepts of PHP, and analyzes an application example, webzine. webzine includes an edit page where the content provider can enter the text of the article, as well as a front-end for presenting the content to the world.

If you are first in touch with PHP, you may be pleasantly surprised to find how easy it is to use in practice. This article is designed to give you a good impression of how PHP works, and then you can determine if it is right for you.

Experience with PHP

This series of articles is divided into two parts, and part 1th explains how the application works (not including installing PHP on your system). You will have the opportunity to try the main index page and peek at how some of the components work behind the scenes. If this is your only motivation, be sure to look at part 2nd, where you'll delve into additional content about the main index page. (Part 2nd also discusses editing components with several sample program examples.) You can download the source code and put your own ideas into practice. )

If you understand HTML and are familiar with any language similar to C (especially Perl), then you understand that the following example should not be a problem. Even if you haven't used much of the language like C, you can still understand these examples. But you do need to know the basics of HTML.

This PHP application sample is a webzine that generates a reader with a simple send module (code not exceeding 3K). The module displays a list of topics. Under each topic heading is a series of article summaries in reverse chronological order. Users can see the entire article by clicking on the title. There is also a slightly more complex editing module that allows any reader to become an author and submit his or her own content. The author must select a category and enter the title of the article, a simple summary, and the full text of the story. If you prefer, you can enter the URL of an image file and click the "Preview" button to verify that everything is ready. The author's input to be validated-even through security checks-will convert all tags except a few secure tags to inactive formats to prevent dangerous or malicious HTML encoding from being executed. For example, the string <applet will become <applet. This conversion actually invalidates the tag.

A dedicated PHP technology

Before studying the actual code for webzine, let's consider a simple example that is a good illustration of the characteristics of PHP. The syntax of PHP allows you to mix HTML statements with PHP statements arbitrarily. This means that HTML statements can appear in the context of loops, if/else statements, functions, and so on. I took advantage of this feature in the webzine program, but the following code sample uses an easier way to make it simpler.

Suppose we have two arrays, $names and $days, that contain information for each month of the year, so $days [0]= 31 and $names [0] = "January", $days [1] equals 28 and $names [1] equals "February" Wait a minute. The following technique is used to create a table that contains days and month names:

Listing 1: Create a table that contains the days and month names

<table border=2>
<tr><th>Name</th><th>Days</th></tr>
<?php

for($i=0; $i<12; $i++) { // 循环开始。
?>
<tr><td><?php

echo($names[$i]) ?></td>
<td><?php

echo($days[$i]) ?></td></tr>
<?php

} // 循环结束。
?>
</table>

Related Article

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.