"; process_entries(); function process_entries() { echo "
\n"; $f = fopen("blog.txt", "r"); $entry = 1; $posts = ""; while (true) { $title = fgets($f); if (!$title) break; $title = trim($title); echo generate_date_div(fgets($f)); echo "
\n"; $link = "$title
"; $posts = $link . $posts; $title = hop($title); echo "

$title

\n"; echo "
\n"; while ($line = fgets($f)) { $line = trim($line); if ($line == ".end") break; if ($line[0] == ".") echo process_dot_line($line); else echo "$line\n"; } echo "
"; echo "\n"; echo "

\n"; $entry += 1; } echo "

My Posts
(most recent first)

$posts
\n"; echo "
\n"; } function hop($s) { $result = ""; for ($i = 0; $i < strlen($s); $i++) { $result .= "$s[$i]"; } return $result; } function process_dot_line($line) { if ($line == ".p") { return "

"; } elseif ($line[2] == " ") { // .X ... $rest = substr($line, 3); return "<{$line[1]}>$rest\n"; } elseif ($line[3] == " ") { if ($line[1] == "r") $float = "right"; else $float = "left"; $src = substr($line, 4); return ""; } } function generate_date_div($date) { $months = "JanFebMarAprMayJunJulAugSepOctNovDec"; $month = substr($months, (substr($date, 0, 2)-1)*3, 3); $day = ltrim(substr($date, 3, 2), "0"); $year = "20" . substr($date, 6, 2); return "

$month $day
$year
\n"; }