以下为引用的内容:
// 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
// replace line breaks with
$html = nl2br(htmlspecialchars($data));
// replace multiple spaces with single spaces
$html = preg_replace('/ss+/', ' ', $html);
// replace URLs with elements
$html = preg_replace('/s(w+://)(S+)/', ' ', $html);
// start building output page
// add page header
$output =<<< HEADER
.slug {font-size: 15pt; font-weight: bold}
.byline { font-style: italic }
HEADER;
// add page content
$output .= "
$output .= "
$output .= "
// add page footer
$output .=<<< FOOTER
FOOTER;
// display in browser
echo $output;
// AND/OR
// write output to a new .html file
file_put_contents(basename($source, substr($source, strpos($source, '.'))) . ".html", $output) or die("Cannot write file");
?>