Home > Backend Development > PHP Tutorial > Video for newbies on the road PHP newbies on the road (5)

Video for newbies on the road PHP newbies on the road (5)

WBOY
Release: 2016-07-29 08:34:56
Original
1113 people have browsed it

Build a simple interactive website (1)
Many features of PHP are related to other software or tools. Using the PHP knowledge we have learned so far, we can try to build a simple interactive website. We can learn a lot through this process. Okay, let's now focus on the construction of a typical personal website.
5.1 Plan a website
Generally, a personal website includes a welcome page, a guestbook page, a bookmark link page, a counter, contact information, and even a photo album and some music files, etc.
5.2 Use include and require for modularization
We look at some websites built with PHP. Almost every page of the website has include and require embedded in the PHP file. This is because using include and require not only enhances the readability of the code, but also divides the site into modules for management. Generally speaking, there will definitely be duplicate content for every page on a website. For example: the navigation bar at the head of the page, advertising icons, or side navigation, etc. There may also be a copyright or some text-based navigation bar in the footer of each page, which is the bottom of the page. If we want to modify content such as the navigation bar or logo on a large website containing hundreds of pages, using our previous methods, we can only make changes to each page. Needless to say, everyone can imagine what an arduous and painful task this is. So, do we have a better solution? The answer is yes. We can put the repeated content into a file, and then use PHP's include and require functions to dynamically call the file on each page that requires this content. In this way, if we want to modify the reused content on all pages in the future, we only need to change the file containing the repeated content.
In order to make it easier for everyone to understand, let us first look at a simple application of include and require:
Start with an HTML page, maybe you will include it (head.htm) in the head of each page of the site.


My personal homepage


Page content (content.htm).


Welcome to my humble abode, although there is nothing here yet.


End of HTML page (trail.htm)


Use include and require functions to separate HTML from PHP, and divide HTML and PHP into modules:
/*
Call the head of the HTML page
*/
require("head.htm");
/*
Call the content of the HTML page
*/
require("centent.htm");
/*
Call the tail of the HTML page
*/
require("trail.htm");
?>
5.3 Let's start with a title page, a contact information page and a resume page. We also need standard, universal page headers and footers.
Title page--front.htm
Here we have a very simple html file:


<br>My personal homepage--Welcome<br>
< ;/HEAD>


My personal homepage



Welcome





Welcome Come to my humble abode, although there is nothing here yet.



But I hope there will be more soon.






Copyright ? Myself, 1999




Contact information page--count.htm
Similarly we have another simple page:


My profile - Contact information




My profile



Contact Information





You can contact me at 1-800-PHP-INFO




HTML to PHP
  As you can see above, every page has the same header and footer.Writing the same information to each page like above is fine when the workload is small, but imagine how much effort you have to expend when there are more than 100 pages and you need to change their header or bottom for them all? What a tedious and boring task it is to manually change page after page! So we should write PHP header and bottom files for these pages, and then we just need to reference them in every HTML page. A file containing PHP code is included in both the include and require functions. Regardless of the file extension, it is treated as a PHP file. We will place these include files in a subdirectory called include and make them files with the .inc suffix. Below we will write the common content of these sites into the file.
Site-wide variable setting: common.inc
//Site-wide variable
$MyEmail = "phptalk@tnc.org";
$MyEmailLink = "$MyEmail";
$MyName = "PHP Talk";
$MySiteName = $MyName."'s Home Page";
?>
Universal page header: header.inc
// Define the general page header
?>


<br><? echo "$MySiteName - $title"; ?> <br>










Universal page bottom: footer.inc
//Universal page bottom
?>



Copyright ? by

, 1999



New page front.php3:
include("include/common.inc");
$title = "Welcome";
include("include /header.inc");
?>


Welcome to my humble abode, although there is nothing here yet.



But I hope there will be more soon.


include("include/common.inc");
?>
New count.php3:
include("include/common.inc");
$title = "Contact Information";
include("include/header.inc");
?>


You can contact me at 1-800-PHP-INFO


< ;?
include("include/footer.inc");
?>
 Now you can appreciate the benefits of this arrangement. If you want to change the header or bottom of the page, you only need to change the corresponding file. If you want to change your e-mail address or even your name, just modify the common.inc file. It's also worth noting that you can include files with any file name or file extension into your file, and you can even include files from other sites.

The above introduces the videos for beginners on the road to PHP (5), including the content of videos for newbies on the road. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template