| 以下为引用的内容:
源代码网整理以下<?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 // replace line breaks with <br /> $html = nl2br(htmlspecialchars($data));
源代码网整理以下// replace multiple spaces with single spaces $html = preg_replace("/ss+/", " ", $html);
源代码网整理以下// replace URLs with <a href...> elements $html = preg_replace("/s(w+://)(S+)/", " <a href="" target="_blank"></a>", $html);
源代码网整理以下// start building output page // add page header $output =<<< HEADER <html> <head> <style> .slug {font-size: 15pt; font-weight: bold} .byline { font-style: italic } </style> </head> <body> HEADER;
源代码网整理以下// add page content $output .= "<div class="slug">$slug</div>"; $output .= "<div class="byline">By $byline</div><p />"; $output .= "<div>$html</div>";
源代码网整理以下// add page footer $output .=<<< FOOTER </body> </html> 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"); ?>
|