Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // set source file name and path
- $source = "php-email.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('/\s\s+/', ' ', $html);
- // replace URLs with <a href...> elements
- $html = preg_replace('/\s(\w+:\/\/)(\S+)/', ' <a href="\\1\\2" target="_blank">\\1\\2</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");
- ?>
Add Comment
Please, Sign In to add comment