既然有上一篇個技巧,當然就可以包成網頁,平常當成一個 utility 來用,這樣若是要轉文章到 bbs 上的話,就可以叫這個網頁出來排版,畫面就可以排得漂漂亮亮啦。:-)

呈現出來的效果如:http://www.jeffhung.idv.tw/html2text.php (目前無法使用)。

<?php
// Author: Chien-Chou Hung
// License: BSDL
?><html>
<head>
<title>html2text</title>
</head>
<body>

<form name="f" method="POST">
    <b>Convert:</b> <input type="text" name="url" value="<?php

    echo (empty($url) ? "http://" : $url);

    ?>" size="50" maxlength="255">
    <input type="submit"><br>
    Text browser:
    <input type="radio" name="browser" value="links" checked>
        links (中文會變亂碼)
    <input type="radio" name="browser" value="lynx">
        lynx
</form>

<hr>

<?php if (!empty($url)) { ?>
<b>URL:</b> <?php echo htmlspecialchars($url); ?>
<form>
<textarea rows="15" cols="80"><?php

if ($browser == "links") {
    $cmd = "/usr/local/bin/links -assume-codepage \"ISO-8859-1\" " .
           "-http-proxy proxy.edu.tw:3128 -dump \"$url\" | " .
           "awk ' /process\$/ { print; exit } { print } '";
}
else if ($browser == "lynx") {
    $cmd = "/usr/local/bin/lynx -dump \"$url\" | " .
           "awk ' /process\$/ { print; exit } { print } '";
}
#echo $cmd;
exec($cmd, $dumps);
for ($i = 0; $i < count($dumps); ++$i) {
    chop($dumps[$i]);
    echo htmlspecialchars($dumps[$i]) . "\n";
}

?></textarea>
</form>
<?php } ?>

</body>
</html>