• ベストアンサー

ファイルの入出力

あるフォルダにはいっているすべてのcsvファイルのデータをひとつのテキストファイルに出力したいのですが、うまくいきません。 わからなかったのでとりあえず、別々のファイルで下記を 実行してみました。 ■指定のフォルダに入っているファイル名をすべて出力。 これはうまくいきました。csvファイルが3つほど入っているのですが、 3つのファイル名が出力されます。 #!/usr/bin/perl opendir(IN,"test/"); while ($filename = readdir(IN)) { $path = "C:/perl/test/$filename"; $source = $filename; print $source,"\n" if -f $path; } ■指定のファイル(a.csv)の中身をtest.htmlとしてファイル出力 これもうまくいきました。カンマ区切りのデータが、 行ごとにあるだけはいっていき、htmlのテーブルにがつがつはいっていきます。 #!/usr/bin/perl my $source = "a.csv"; open (IN, $source) or die "$!"; my $dest = "test.html"; open (OUT, ">$dest") or die "$!"; print OUT '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=shift_jis" /> <title>無題ドキュメント</title> <style type="text/css"> <!-- .style1 {color: #FFFFFF} --> </style> </head> <body> <table width="419" height="105" border="0" cellpadding="0" cellspacing="0"> <tr> <th bgcolor="#000000"><span class="style1">名前</span></th> <th bgcolor="#000000"><span class="style1">住所</span></th> <th bgcolor="#000000"><span class="style1">性別</span></th> </tr>'; while (<IN>) { chomp; @data = split(/,/, $_); print OUT "<tr>\n"; print OUT "<th bgcolor=\"#666666\">",$data[0],"</th>\n<td>",$data[1],"</td>\n<td>",$data[2],"</td>\n"; print OUT "</tr>\n"; } print OUT "</table> </body> </html>"; つまり、この二つを1ファイルにまとめたいのです。 一個目で取得したファイル名リストを 2個目のopen で順次ファイルの中身を取っていってほしいのです。 いったんファイル名をテキストファイルに出力してから、 それを読む方法もあったのですが、 できたら、ファイルを出力せずに変数からそのまま、 ファイル名の一覧を取得したいと思っています。 どなたか教えていただけますでしょうか。

  • Perl
  • 回答数2
  • ありがとう数2

質問者が選んだベストアンサー

  • ベストアンサー
  • metis
  • ベストアンサー率52% (86/165)
回答No.1

#!usr/bin/perl opendir(DIR,"test/"); $dest = "test.html"; open (OUT, ">$dest") or die "$!"; while ($filename = readdir(DIR)) { $path = "test/$filename"; $source = $filename; if(-f $path){ open (IN, $path) or die "$!"; print OUT '<!DOCTYPE html PUBLIC (以下、表の1行目が終わるまで略) while (<IN>) { chomp; @data = split(/,/, $_); print OUT "<tr>\n"; print OUT "<th bgcolor=\"#666666\">",$data[0],"</th>\n<td>",$data[1],"</td>\n<td>",$data[2],"</td>\n"; print OUT "</tr>\n"; } close(IN); } } closedir(DIR); (3行略) close(OUT); こんな感じでしょうか。 ポイントは ・1つ目のでファイルを見つけるごとに2つ目の処理を実行する。 ・出力先ファイルは先に開いておいて、最後まで閉じない この辺りでしょうか。 詳しくはソースの違いを良く見て理解して下さい。 自分でひとつにまとめた時(動かなかったものですね)のソースも手元に置いて、比較すればなお良しです。 分からなければ補足しますが。 ちなみに、コードには、私なりのスタイルが入っててその辺りごっちゃになってますが、まぁ、何とかなるかと思います。

trfnc223
質問者

お礼

ご回答ありがとうございます! 考え方は理解できたような気がします! whileを入れ子にするんですね。 ちょっと試してみます! もしかしたらまたおたずねするかもしれません。 その時はどうかよろしくお願いします。。。。

その他の回答 (1)

  • sakusaker7
  • ベストアンサー率62% (800/1280)
回答No.2

検索対象のディレクトリには .csv以外のファイルもなかったりしないのでしょうか? あと、ディレクトリを再帰的に潜って行くこともしないでいいのですよね? opendirで自分でディレクトリエントリを読んで行くとファイルの振り分け とかが面倒だと思うので、globを使ってみました。 #!/usr/bin/perl use strict; use warnings; my $targetdir = shift || 'test'; my @filelist =glob( $targetdir . '/*.csv' ); open my $of, '>', 'output.html' or die; print $of <<END_OF_HEADER; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "?http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">? <html xmlns="?http://www.w3.org/1999/xhtml">? <head> <meta http-equiv="Content-Type" content="text/html; charset=shift_jis" /> <title>無題ドキュメント</title> <style type="text/css"> <!-- .style1 {color: #FFFFFF} --> </style> </head> <body> <table width="419" height="105" border="0" cellpadding="0" cellspacing="0"> <tr> <th bgcolor="#000000"><span class="style1">名前</span></th> <th bgcolor="#000000"><span class="style1">住所</span></th> <th bgcolor="#000000"><span class="style1">性別</span></th> </tr> END_OF_HEADER foreach my $file (@filelist) { open my $if, '<', $file or warn "can't open $file"; while (<$if>) { my @fields = split q{,}, $_; print $of <<END_OF_TEMPLATE; <tr> <th bgcolor="#666666">$fields[0]</th> <td>$fields[1]</td> <td>$fields[2]</td> </tr> END_OF_TEMPLATE } close $if; } print $of <<END_OF_TRAILER; </table> </body> </html> END_OF_TRAILER close $of; ヘッダとかトレイラーのところはサブルーチンにしたいところですが とりあえずはこんなところで。

trfnc223
質問者

お礼

ご回答ありがとうございます! なにぶん初心者なものでglobというものを使ったことがなかったのですが、 とりあえず実行してみたらきれいにできました。 いただいたコードをひもといて自分で勉強したいと思います! ありがとうございました!!

関連するQ&A

  • ファイルの入出力2

    指定したフォルダ内にあるcsvファイルのデータを 指定したhtmlファイルに出力するプログラムを書いているのですが、 下記のままだとcsvファイルにあるすべてのデータをとってきてしまいます。実現させたいことは「指定したフォルダ内にあるcsvファイル2行目のデータだけファイル出力する」というものです。 どなたかご協力お願いします。 #!/usr/bin/perl #--------------------------------------------------------------# # ディレクトリを開く #--------------------------------------------------------------# opendir(DIR,"test/"); #--------------------------------------------------------------# # 出力ファイル名を指定 #--------------------------------------------------------------# $dest = "test.html"; open (OUT, ">$dest") or die "$!"; #--------------------------------------------------------------# # 出力ファイルにhtmlを出力 #--------------------------------------------------------------# print OUT '<html> <head> <title>無題ドキュメント</title> <style type="text/css"> <!--.style1 {color: #FFFFFF}--> </style> </head> <body> <table width="419" height="105" border="0" cellpadding="0" cellspacing="0"> <tr> <th bgcolor="#000000"><span class="style1">名前</span></th> <th bgcolor="#000000"><span class="style1">住所</span></th> <th bgcolor="#000000"><span class="style1">性別</span></th> </tr>'; #--------------------------------------------------------------# # ディレクトリにあるファイル名を取得 #--------------------------------------------------------------# while ($filename = readdir(DIR)) { # ディレクトリにあるファイルパスを取得 $path = "test/$filename"; if(-f $path) { # ファイルオープン open (IN, $path) or die "$!"; while (<IN>) { # カンマ区切りでデータを取得&改行削除 chomp(@data = split(/,/, $_)); print OUT "<tr>\n"; # 各行の3つのカンマ区切りデータを取得 print OUT "<th bgcolor=\"#666666\">",$data[0],"</th>\n<td>",$data[1],"</td>\n<td>",$data[2],"</td>\n"; print OUT "</tr>\n"; } close(IN); } } #--------------------------------------------------------------# # ディレクトリを閉じる #--------------------------------------------------------------# closedir(DIR); print OUT "</table> </body> </html>"; #--------------------------------------------------------------# # ファイルを閉じる #--------------------------------------------------------------# close(OUT);

    • ベストアンサー
    • Perl
  • CSVデータベース

    PHPを使い CSVのデータを表示させる事ができました。 がっ見た目がどうも汚いですよね・・・ もっとすっきりする方法はあるんでしょうか? あとCSVのデータを検索させるようにしたいのですが何かサンプルとかありませんでしょうか? 注文多くて申し訳ないですが、是非ともご教授よろしくお願い致します。 <table width="550" class="table01"> <tr> <td width="32" height="18"><div align="center"><strong>画像</strong></div></td> <th width="123"><strong>情報1</strong></th> <th width="58"><strong>情報2</strong></th> <th width="56"><strong>情報3</strong></th> <th width="53"><strong>情報4</strong></th> <th width="55"><strong>情報5</strong></th> <th width="56"><strong>情報6</strong></th> <th width="81"><strong>対象</strong></th> </tr> <?php $csv = fopen ("./data/new.csv", "r") or die(print "ファイルを開く事が出来ませんでした"); while ($items = fgetcsv ($csv, 1000,",")) { print "<tr>\n"; print "<td height='40' rowspan='2'><img src='$items[0]'/></td>\n"; print "<td><center>$items[1]<center></td>\n"; print "<td>$items[2]</td>\n"; print "<td>$items[3]</td>\n"; print "<td>$items[4]</td>\n"; print "<td>$items[5]</td>\n"; print "<td>$items[6]</td>\n"; print "<td>$items[7]</td>\n"; print "</tr>\n"; print "<tr>\n"; print "<td height='16' colspan='7'><div align='left'>$items[8]</div></td>\n"; print "</tr>\n"; } fclose($csv); ?> </table>

    • ベストアンサー
    • PHP
  • HTMLのテーブルタグでCSVデータ表示

    HTML素人です。 色々参考にしていますが、どうしてもわからず困っています。 もし分かる方がいましたら、ご教示お願い致します。 見よう見まねで下記のようなHTMLのテーブルを作成したのですが、 この見出しの下のデータ部分から、指定の格納フォルダに保存しているCSVデータを読み込んで表示させるといったことがしたいです。 (できれば、フォルダ内に新たにCSVデータが保存されたとき、 一度読み込んだファイルの次から表示されるようにしたいです。) 大変恐縮ですが、ご教示お願い致します。 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>発注書</title> </head> <body> <header> <h1>発注書</h1> </header> </body> <table border> <tr> <th bgcolor="#00ffff">No</th> <th bgcolor="#00ffff">商品</th> <th bgcolor="#00ffff">商品名</th> <th bgcolor="#00ffff">数量</th> <th bgcolor="#00ffff">金額</th> <th bgcolor="#00ffff">合計金額</th> <th bgcolor="#00ffff">コメント</th> <th bgcolor="#00ffff">備考①</th> <th bgcolor="#00ffff">備考②</th> <th bgcolor="#00ffff">備考③</th> </tr> <tr> <td>2-1</td> <td>2-2</td> <td>2-3</td> <td>2-4</td> <td>2-5</td> <td>2-6</td> <td>2-7</td> <td>2-8</td> <td>2-9</td> <td>2-10</td> </tr> <tr> <td>3-1</td> <td>3-2</td> <td>3-3</td> <td>3-4</td> <td>3-5</td> <td>3-6</td> <td>3-7</td> <td>3-8</td> <td>3-9</td> <td>3-10</td> </tr> </table> </html>

  • CSVファイルより自動でHTML形式で表示したい。

    CSVファイルより自動でHTML形式で表示したいのです。 たとえば、csv ファイルの中身が、 room.csv 部屋名,温度,湿度,料金 101,23.5,40,15000 102,23.2,40,16000 103,23.0,40,17000 104,23.4,40,19000 となっているとします。 room.htmlでもroom.cgi 等で表示させ ブラウザのソースを見たときには、 <table border=4 width=250 align=center> <tr bgcolor="#cccccc"> <th>部屋名</th> <th>温度</th> <th>湿度</th> <th>料金</th> </tr> <tr align=center> <td>101</td> <td>23.5</td> <td>40</td> <td>15000</td> </tr> <tr align=center> <td>102</td> <td>23.2</td> <td>40</td> <td>16000</td> </tr> <tr align=center> <td>103</td> <td>23.0</td> <td>40</td> <td>17000</td> </tr> <tr align=center> <td>104</td> <td>23.4</td> <td>40</td> <td>19000</td> </tr> </table> のように、したいのですが、 可能でしょうか? perl等のプログラムの知識は、ほとんどありません。 作ってあるものをアップロードして動くようにすることは、出来ます。

  • パーサーについて

    初心者です。 PHP5を始めて約50時間程度です。 パーサーについての質問です。 パーサー=fgetss()関数のことなのでしょうか。 下記プログラムは理解できるのですが(動作確認済み)、 下記htmlファイルをCSV形式に変換したいのです。 --下記プログラム <? $files = fopen("test.html", "r"); while( ($point = fgetss($files, 1024 )) !== false) { print $point; } ?> --以上下記プログラム ---以下htmlファイルのソース <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "​http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">​ <html xmlns="​http://www.w3.org/1999/xhtml">​ <head> </head> <body> <TABLE width="95%" border="1" cellpadding="4" cellspacing="0" bordercolor="#999999"> <tr> <td width="42%" align="CENTER" bgcolor="#BFBFDF"><font size="-1"><b>テーマ</b></font></td> <td width="9%" align="CENTER" bgcolor="#BFBFDF"><b><font size="-1">課目</font></b></td> </tr><tr> <td valign="MIDDLE" bgcolor="#FFFFFF"><a href="abc.html">テーマ1</a></td> <td valign="MIDDLE" align="CENTER" bgcolor="#c8e3e3">課目1</td> </tr><tr> <td valign="MIDDLE" bgcolor="#FFFFFF"><a href="DEF.html">テーマ2</a></td> <td valign="MIDDLE" align="CENTER" bgcolor="#ffffe0">課目2</td> </tr> </TABLE> </body> </html> ---ソース以上

    • ベストアンサー
    • PHP
  • マウスオーバー時テーブルの背景色を変えているのですが

    質問させていただきます。 テーブルを作成してマウスオーバーしている行の バックカラーを変えるプログラムを作成しています。 ですが、rowspanを使用すると、rowspanが別の行 扱いになり、バックカラーが変えられなくなってしまいました。 一緒にしたい場合どうしたら良いでしょうか。 もしわかりましたらご教授下さい。 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <meta http-equiv="Content-Style-Type" content="text/css"> <script type="text/javascript"><!-- firstcolor="#ffffff"; //初めの色 nextcolor="#eeeeee"; //変更後の色 function table_row(table_id){ tobj=document.getElementById(table_id).tBodies[0]; for (i=0; i<tobj.rows.length;i++){ tobj.rows[i].onmouseover=function(){this.style.backgroundColor=nextcolor}; tobj.rows[i].onmouseout=function(){this.style.backgroundColor=firstcolor}; } }// --></script> </head> <body> <table border=1 id="data_table2"> <thead> <tr> <th>No</th><th>DATA1</th><th>DATA2</th><th>DATA3</th> </tr> </thead> <tbody> <tr> <td>No</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td> </tr> <tr> <td>No</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td> </tr> <tr> <td rowspan="2">&nbsp;</td><td rowspan="2">&nbsp;</td><td>DATA</td><td>DATA</td> </tr> <tr> <td colspan="2">&nbsp;</td> </tr> <tr> <td>No</td><td>DATA</td><td>DATA</td><td>DATA</td> </tr> </tbody> </table> <script>table_row("data_table2")</script> </body> </html>

  • 複数のCSVファイルを1つの表にして出したい

    あるCSVファイルを、Perl+HTMLで、プラウザに「表」で表示させるようにしました。 しかし、追加で複数のCSVファイルを読み込ませて、同じ表に入れることができません。(今ある表のなかの、$r1,2,3と番号が存在してる以外の空欄になっている表に入れたいのです) どのようにすればいいのか、どなたかお教え下さい!>< ちなみに、今作ってあるものはこんなかんじです。 動作確認済み。 #!/usr/local/bin/perl #----------------------------------- $file = "a.20090504.csv"; #----------------------------------- print "Content-type: text/html\n\n"; print "<html>\n"; print "<body>\n"; print "<br><br>\n"; print "<center>\n"; print "<table border=1 >\n"; $days = $file; $days =~ s/a.//g; $days =~ s/.csv//g; open(IN,"$file"); @kasou = <IN>; close(IN); foreach $line (@kasou){ ($r1, $r2, $r3, $r4, $r5, $r6, $r7) = split (/,/, $line); print "<tr>\n"; print "<td>$days</td>\n"; print "<td>$r1</td>\n"; print "<td></td>\n"; print "<td>$r2</td>\n"; print "<td></td>\n"; print "<td></td>\n"; print "<td>$r3</td>\n"; print "<td></td>\n"; print "<td></td>\n"; print "<td>$r4</td>\n"; print "<td>$r5</td>\n"; print "<td>$r6</td>\n"; print "<td>$r7</td>\n"; print "</tr>\n"; } print "</table>\n"; print "</body>\n"; print "</html>\n"; ※ちなみに、これですとCSVファイル名の20050504だけがtrに入るようになっています。これは、こうしたいのでこうしているのですが、繰り返しtrに投入されるようになっているのも気になります。 どうしたら直るでしょうか。

  • テーブルでのハイライト表示について教えて下さい

    皆さんこんばんわ。 いつも利用させてもらっています。 HTMLとJAVA SCRIPTの初心者です。 テーブルでのonmauseoverになっている時のハイライトにする 方法を教えて下さいTT trをハイライトにするという内容の質問はありましたが、 今回は途中で背景色が変わるため、 どうしても作ることができませんでした。 一つ一つIDをふり、onmouseoverでの処理をさせてみましたが、 FirefoxではDOCTYPEの違いからか、エラーが出て表示することが できませんでした。 項目的には残り100項目ほどありますので、どなたかお教え いただけませんでしょうかTT よろしくお願いします。 以下、ソースです。 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <head> <script type="text/javascript"> function TDBC0() { //背景を設定 TD1.style.background='#FFFFCC'; TD1.style.background='#FFFFCC'; TD2.style.background='#FFFFCC'; TD3.style.background='#FFFFCC'; TD4.style.background='#FFFFCC'; TD5.style.background='#FFFFCC'; TD6.style.background='#FFFFCC'; TD7.style.background='#FFFFCC'; } function TDBC0C() { //背景を元に戻す TD1.style.background='#f1f1e0'; TD2.style.background='#f1f1e0'; TD3.style.background='#ffffff'; TD4.style.background='#ffffff'; TD5.style.background='#f1f1e0'; TD6.style.background='#fafaf5'; TD7.style.background='#fafaf5'; } //身体測定 体重 function TDBC1() { //背景を設定 TD1.style.background='#FFFFCC'; TD1.style.background='#FFFFCC'; TD2.style.background='#FFFFCC'; TD3.style.background='#FFFFCC'; TD4.style.background='#FFFFCC'; } function TDBC1C() { //背景を元に戻す TD1.style.background='#f1f1e0'; TD2.style.background='#f1f1e0'; TD3.style.background='#ffffff'; TD4.style.background='#ffffff'; } //身体測定 体重 function TDBC2() { //背景を設定 TD1.style.background='#FFFFCC'; TD1.style.background='#FFFFCC'; TD5.style.background='#FFFFCC'; TD6.style.background='#FFFFCC'; TD7.style.background='#FFFFCC'; } function TDBC2C() { //背景を元に戻す TD1.style.background='#f1f1e0'; TD5.style.background='#f1f1e0'; TD6.style.background='#fafaf5'; TD7.style.background='#fafaf5'; } </script> <head> <body> <table border="1" cellpadding="0" cellspacing="0" class="tbl004"> <tr> <th rowspan="2" bgcolor="#C4E5FA" class="bg1">分 類</th> <th rowspan="2" bgcolor="#C4E5FA" class="bg1">種類</th> <th colspan="2" bgcolor="#C4E5FA" class="bg1">在庫数</th> </tr> <tr> <th bgcolor="#C4E5FA" class="bg1">下 限</th> <th bgcolor="#C4E5FA" class="bg1">上 限</th> </tr> <tr> <th rowspan="2" bgcolor="#f1f1e0" class="tdBgcolor02" id="TD1" onmouseover="TDBC0()" onmouseout="TDBC0C()">書籍</th> <td bgcolor="#f1f1e0" class="tdBgcolor02" id="TD2" onmouseover="TDBC1()" onmouseout="TDBC1C()">単行本</td> <td bgcolor="#ffffff" id="TD3" onmouseover="TDBC1()" onmouseout="TDBC1C()">50</td> <td bgcolor="#ffffff" id="TD4" onmouseover="TDBC1()" onmouseout="TDBC1C()">270</td> </tr> <tr> <td bgcolor="#f1f1e0" id="TD5" onmouseover="TDBC2()" onmouseout="TDBC2C()" class="tdBgcolor02">文庫本</td> <td bgcolor="#cccccc" id="TD6" onmouseover="TDBC2()" onmouseout="TDBC2C()" class="tdBgcolor03">10</td> <td bgcolor="#cccccc" id="TD7" onmouseover="TDBC2()" onmouseout="TDBC2C()" class="tdBgcolor03">300</td> </tr> </table> </body> </html>

  • データ)表示件数について

    PHPとCSVでデータを表示させる事は出来ました。 希望は、 Pagerを使い1ページに表示する件数を10件としたいのですが、うまくいきませんでした。 よろしければ修正 or ご教授よろしくお願い致します。 <?php require("Pager/Pager.php"); $params = array( 'mode' => 'sliding', 'perPage' => 20, 'delta' => 5, 'urlVar' => 'p', 'separator' => ' |', 'curPageSpanPre' => '', 'curPageSpanPost' => '', 'prevImg' => '&lt;前の20件', 'nextImg' => '次の20件&gt;', 'firstPageText' => '最初', 'firstPagePre' => '[', 'firstPagePost' => ']', 'lastPageText' => '最後', 'lastPagePre' => '[', 'lastPagePost' => ']', 'spacesBeforeSeparator' => 0, 'spacesAfterSeparator' => 1, 'totalItems' => 1000, 'altFirst' => '最初のページへ移動', 'altPrev' => '前のページへ移動', 'altNext' => '次のページへ移動', 'altLast' => '最後のページへ移動', 'altPage' => 'ページ', ); $pager =& Pager::factory($params); $links = $pager->getLinks(); if ($links['pages'] != '') { echo $links['first'], $links['back'], ' | ', $links['pages'], ' | ', $links['next'], ' ', $links['last']; } print<<<eof <table width="550" class="table01"> <tr> <td width="32" height="18"><div align="center"><strong>画像</strong></div></td> <th width="123"><strong>名前</strong></th> <th width="58"><strong>材料</strong></th> <th width="56"><strong>時間</strong></th> <th width="53"><strong>費用</strong></th> <th width="55"><strong>美味しさ</strong></th> <th width="56"><strong>日</strong></th> <th width="81"><strong>詳細ページ</strong></th> </tr> eof; $csv = fopen ("item.csv", "r") or die(print "ファイルを開く事が出来ませんでした"); while ($items = fgetcsv ($csv, 1000,",")) { print "<tr>\n"; print "<td height='40' rowspan='2'><img src='$items[0]'/></td>\n"; print "<td><center>$items[1]<center></td>\n"; print "<td>$items[2]</td>\n"; print "<td>$items[3]</td>\n"; print "<td>$items[4]</td>\n"; print "<td>$items[5]</td>\n"; print "<td>$items[6]</td>\n"; print "<td>$items[7]</td>\n"; print "</tr>\n"; print "<tr>\n"; print "<td height='16' colspan='7'><div align='left'><a href="$items[8]"></a></div></td>\n"; print "</tr>\n"; } fclose($csv); ?>

    • ベストアンサー
    • PHP
  • html→xmlの変換

    後述するようなhtmlファイルがあります。 これをxmlに変換する事は可能なのでしょうか。 また、もし可能なら、その方法、ソフトなども教えていただけると幸いです。 ---以下ソース <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> </head> <body> <TABLE width="95%" border="1" cellpadding="4" cellspacing="0" bordercolor="#999999"> <tr> <td width="42%" align="CENTER" bgcolor="#BFBFDF"><font size="-1"><b>テーマ</b></font></td> <td width="9%" align="CENTER" bgcolor="#BFBFDF"><b><font size="-1">課目</font></b></td> </tr><tr> <td valign="MIDDLE" bgcolor="#FFFFFF"><a href="abc.html">テーマ1</a></td> <td valign="MIDDLE" align="CENTER" bgcolor="#c8e3e3">課目1</td> </tr><tr> <td valign="MIDDLE" bgcolor="#FFFFFF"><a href="DEF.html">テーマ2</a></td> <td valign="MIDDLE" align="CENTER" bgcolor="#ffffe0">課目2</td> </tr> </TABLE> </body> </html> ---ソース以上

    • ベストアンサー
    • XML

専門家に質問してみよう