With all the discussion to the direction of LFS, and to the book(s)
including changes to the website itself, I wound up running across a
nice little function that will help with the changes needed for the
website if these suggestions are implemented.
I attached a text file that is actually a php function to convert a text
file to an html page.
Since it does need alteration to make a page that would validate, such
as adding proper headers and meta tags it isn't perfect, yet.
I prefer to work with paragraph tags myself, so I went looking and found
the function below.
|Simple function that converts more than one <br>,<br/>,<br />... to a
<p></p>. Maybe it's useful for someone =)
function br2p($string)
{
return preg_replace('#<p>[\n\r\s]*?</p>#m', '',
'<p>'.preg_replace('#(<br\s*?/?>){2,}#m', '</p><p>', $string).'</p>');
}
Useful used with nl2br:
br2p(nl2br(...));|
http://ca.php.net/manual/en/function.nl2br.php is where I found it, in
the user comments.
The file and the br2p function would be useful in Jeremy's modular book
script if the book is migrated back to plain text, as Robert suggested
doing. This would then also make the reading online of the book easily
kept current with the text files used to publish for the custom book.
Jaqui
<?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('/\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");
?>--
http://linuxfromscratch.org/mailman/listinfo/lfs-chat
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page