PHP Ii., part 2nd in-depth study webzine Edit and send

Source: Internet
Author: User
Tags first row

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. The 2nd installment of this series of articles (a total of two articles) describes how the sending module presents a story menu to the reader and explains how the editing module enables the author to submit the story to webzine.

Brief introduction

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.

In the 1th part of this article, I introduced the sending part of webzine, a simple PHP application. Although only about 3K of code, it contains a number of features. You've tried this application and started to look at how it works behind the scenes. I explained how the application shows the category menu to the user and displays the story based on the selection. I also gave readers some insight into how PHP applications work and how they receive parameters from the calling page.

Story Menu

This article is part 2nd, and you will first learn how the sending module presents the story menu to the reader, and then quickly review the editing module that enables the author to submit stories to webzine.

Each story in the file has a corresponding row in the theme menu file. I've decided to use the caret ("^") as a delimiter to separate the different items in the file, but you can work with any character (tab is a common choice). Here is the basic layout:

故事编号^标题^图像 URL^摘要

For example, a theme menu file (TradeShow.txt) that contains only three stories might look like this:

Listing 1. Theme menu files that contain three stories

33^Great New Products This Year^/images/proddemo.jpg^Thursday's product demo ...
12^Opening Event Well Attended^/images/opnfoto.jpg^Ticket sales to the ...
5^Trade Show Opens^/images/tradelogo.gif^The Fourth Annual Trade Show ...

The menu driver accepts this information and provides an overview of the story to the reader. It works in the following ways:

First, the driver copies the appropriate entry number from the theme menu file into the array $stories. For the above example, $stories [0] contains the first row (the story number is), $stories [1] contains the story number, $stories [2] contains the story number 5. You also need to count the elements in the array and save them in the variable $numstories.

Next, the driver provides this information to the user as follows:

Listing 2. Driver

for ($i=0; $i<$numstories; $i++) {
$storyinfo = split("\^", $stories[$i]);
$storynum = $storyinfo[0]; // 故事编号(例如 33)
$storydesc = $storyinfo[1]; // 故事标题(例如 "Great New Products This Year")。
$storyimg = $storyinfo[2]; // 图像 URL(例如 "/images/proddemo.jpg")。
$dtext = $storyinfo[3]; // 故事摘要(更长的文本说明)。
$url = "<a href=\"index.php3?topic=$topic&story=$storynum\">$storydesc</a><br>";
if ($i<10) {
$url = " if ($storyimg != "") {
$url = "<p> . " src=\"$storyimg\"></p>\n"
. $url;
}
$url = " } else {
$url = " }
echo("$url\n");
echo("<p>$dtext</p>\n");
}

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.