Home php教程 PHP源码 php 静态化页面 生成静态页面

php 静态化页面 生成静态页面

Jun 08, 2016 pm 05:31 PM
html mysql php text

<script>ec(2);</script>
前言:

目前网络上好多网站的新闻发布系统都采用了动态服务器技术生成静态HTML的做法,这样做的好处是:一是能减轻其服务器的负担,二是因为生成了HTML静态页面,所以其网站被搜索引擎搜索到的机率更大一些。笔者的网站曾经使用PHP这一动态技术来构建新闻发布系统,其原理也就是应用了PHP生成HTML静态页面的技术,相关平台是 Windows XP Sp2+php4.32+mysql,因此,在这里,想简单地谈一下这种做法的思路。这篇文章适合于对PHP+MYSQL数据库操作,SQL语句以及网页设计有点基础的朋友,如果您是一个从头开始学的朋友,那么请先打好基础吧!到这里就不用往下看了。如果您都符合上述条件的话,那么恭喜您,请接着往下看。但是,在具体动手构建之前,您还要做好以下几点准备工作。

一、 具备本地调试PHP的功能

在WINDOWS XP操作系统下,笔者建议你可以到网上下载一个PHP+MYSQL+APHCHE的服务器套装,如华军软件园,去那里搜索一下就可以下载到。下载完后默认安装即可,这样您就具备了在本地测试PHP的功能了,省去了很多手动配置的麻烦,怎么样,简单吧,OK,这仅仅只是第一步。

二、 构思新闻发布系统所具备的功能

首页的新闻发布往往是通过后台更新的,后台的更新无非是由添加、编辑、删除数据等基本的功能所实现的。在这里,你可以使用网页设计软件来构建你的想要的后台界面,其功能的实现当然是要用到PHP喽。这一步建议您先想好新闻发布系统要有的功能。在这里,如何用PHP添加、编辑、删除数据就不再重复,因为重点是如何在这基础上生成静态技术。

三、 PHP生成HTML的技术原理。

哈哈。费话说了那么多,终于到了该讲的地方了。其实,这一原理并不复杂,综合地来讲的话,应该是PHP中一个替换数据语法的应用。OK,讲一个简单范例吧,一步一步地分析!相信聪明的你能看得明白的咯,仔细看好每一步即可,在这里,只是引导大家如何做而已,具体的可以实践一下!

(1)在MYSQL里新建一数据库,命名为 database (可自定义),新建一表,命名为 news(因为是新闻发布嘛,取个好记的名字即可,可自定义),然后建立这几个字段名:
id (自动递增,这是关键,类型:INT)
title (顾名思义,新闻标题,类型可取 TEXT)
content (新闻内容,类型可取 TEXT)
path (HTML文件路径,类型可取 TEXT)

(2)建立 conn.php
这是连接数据库的PHP文件,你可以把连接数据的语句单独放在这一文件里,以后多个需要连接数据库的文件直接引用这个文件即可。

(3)设计添加新闻的表格 add.form 简单的源代码如下:

//提交至 add.php
新闻标题:

新闻内容:

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the &quot;MySQL Native Password&quot; plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

See all articles