列表A
让我们来看看它是如何工作的:
// 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 HEADER; // add page content $output .= " $slug "; $output .= " By $byline "; $output .= " $html "; // 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"); ?>