]text2htmllist v1.6 公開

入力したテキストをHTMLリスト形式で返します.

<?php @header('Content-type: text/html;charset=Shift_JIS');

/* script_name: text2htmltext
 * author: sigma
 * author_link: http://sigma.s22.xrea.com/
 * license: The GNU General Public License
 * exposition: 
 *    1行1行をli要素として受け止めます.
 *    ulかolかdlかの選択をしてください.
 *    dlのとき,奇数行をdt,偶数行をddにします.
 * memo (時間はJST): 
 *    2005-09-14 21:04:11 v1.0 完成.dl対応への夢
 *    2005-09-15 12:39:44 v1.5 dl対応
 *    2005-09-16 10:50:53 v1.6 変換元データにtrimを掛けた
 */

define("APP_NAME", "text2htmllist");
define("PHP_SELF", "text2htmllist.php"); // 自分のファイル名

?><html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<title><?php echo APP_NAME; ?></title>
</head>
<body>

<!-- ##### データ表示のフォーム ##### -->
<?php
// ポストデータの存在確認
if(trim($_POST['src'])){
?><fieldset><legend>変換後データ表示フォーム</legend>
<form><textarea><?php
    // 改行コード統一し,配列へ
    $lines = explode("\n", str_replace("\r", "\n", str_replace("\r\n", "\n", stripslashes(trim($_POST['src'])))));
    
    // $_POST['kaigyo_output']から改行設定
    switch($_POST['kaigyo_output']){
        case "cr": $kaigyo = "\r"; break;
        case "lf": $kaigyo = "\r\n"; break;
        case "crlf": $kaigyo = "\r\n"; break;
    }

    // 表示
    if($_POST['listtype']=="dl"){
        echo "<".$_POST['listtype'].">".$kaigyo;
        for($i=0; $lines[$i+1]!=NULL; $i+=2)
            echo "<dt>".$lines[$i]."</dt><dd>".$lines[$i+1]."</dd>".$kaigyo;
        echo "</".$_POST['listtype'].">".$kaigyo;
    }else{
        echo "<".$_POST['listtype'].">".$kaigyo;
        foreach($lines as $line)
            echo "<li>$line</li>".$kaigyo;
        echo "</".$_POST['listtype'].">".$kaigyo;
    }

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

<!-- ##### データ送信のフォーム ##### -->
<form action="<?php echo PHP_SELF; ?>" method="POST">
<fieldset><legend>データ送信フォーム</legend>
<textarea name="src"></textarea><input type="submit"></input>
<fieldset><legend>リスト形式</legend>
<input id="ul" type="radio" name="listtype" checked value="ul"></input><label for="ul">順不同リストもしくは箇条書き / Unordered List</label><br>
<input id="ol" type="radio" name="listtype" value="ol"></input><label for="ol">順序つきリスト / Ordered List</label><br>
<input id="dl" type="radio" name="listtype" value="dl"></input><label for="dl">定義リスト / Definition List</label>
</fieldset>
<fieldset><legend>改行コード変換</legend>
<input id="del" type="radio" name="kaigyo_output" checked value=""></input><label for="del">削除 (from CR or LF or CR+LF)</label><br>
<input id="cr" type="radio" name="kaigyo_output" value="cr"></input><label for="cr">CR (from LF or CR+LF)</label><br>
<input id="lf" type="radio" name="kaigyo_output" value="lf"></input><label for="lf">LF (from CR or CR+LF)</label><br>
<input id="crlf" type="radio" name="kaigyo_output" value="crlf"></input><label for="crlf">CR+LF (from CR or LF)</label>
</fieldset>
<input type="submit"></input>
</fieldset>
</form>
<div> - <a href="http://sigma.s22.xrea.com/"><?php echo APP_NAME; ?></a> - </div>
</body>
</html>