background image

  相当标准的文本:它有一个标题、一个署名和很多段的文字。把这篇文档转换成为

HTML 真正需要做的是使用 HTML 的分行和分段标记把原文的布局保留在 Web 页

面上。特殊的标点符号需要被转换成为对应的

HTML 符号,超链接需要变得可以点

击。

  下面的

PHP 代码(列表 A)就会完成上面所有的任务:

  列表

A

让我们来看看它是如何工作的:

以下是引用片段:

<?php

// set source file name and path

$source = "toi200686.txt";

// read raw text as array

$raw = file($source) or die("Cannot read file");

// retrieve first and second lines (title and author)

$slug = array_shift($raw);

$byline = array_shift($raw);

// join remaining data into string

$data = join('', $raw);

// replace special characters with HTML entities