質問

私はこのテキストファイル:

Dec 04 20:15 Naruto 123
Dec 04 17:42 Naruto 98
Dec 04 16:19 D Gray Man 001
Dec 04 16:05 Bleach 128
Dec 04 12:13 50 x 50 44

ための出力コンテンツのテーブルの日時、そのカラムのタイル及び章にしています。

も..I交換する必要があり、タイトル及び章においてリンクする形式のこのように:

<a href="/title/title chapter">title chapter</a>

のための明確化のタイトルのテキストファイル:

Naruto
Naruto
D Gray Man
Bleach
50 x 50

の章の内数。

123
98
001
128
44
役に立ちましたか?

解決

  1. ファイルの読み込み、店舗各線、配列になります。
  2. Open <table> タグ
  3. ループの配列を抽出の日付/時間/title/第用regex.

こちらは正規表現を開始するために変更することにしているお客様のニーズ:

/^([a-zA-Z]{3}\s\d{2})\s(\d{2}:\d{2})\s(.+?)\s(\d+)\s*?$/
//$1 contains date : "Dec 04"
//$2 contains time : "20:15"
//$3 contains the title : "Naruto"
//$4 contains the chapter : "123"

各項目の配列には、適切な <tr> & <td> タグに抽出したデータです。

更新:

<?php
$filedata = "Dec 04 20:15 Naruto 123
Dec 04 17:42 Naruto 98
Dec 04 16:19 D Gray Man 001
Dec 04 16:05 Bleach 128
Dec 04 12:13 50 x 50 44";

$lines = explode("\n", $filedata);

echo "<table border=\"1\">";

foreach($lines as $line)
{
    echo "<tr>";
    preg_match("/^([a-zA-Z]{3}\s\d{2}\s\d{2}:\d{2})\s(.+?)\s(\d+)\s*?$/", $line, $matches);
    echo "<td>$matches[1]</td>";
    echo "<td><a href=\"/$matches[2]/$matches[2] $matches[3]\">$matches[2] $matches[3]</a></td>";
    echo "</tr>";
}
echo "</table>"
?>

他のヒント

トリックを行う必要があり、このような何かが(コードをテストしていません):

$data = Explode ( "\n", File_Get_Contents ( 'yourfile' ) );

foreach ( $data as $key => $line )
{
    $tmp = Explode ( ' ', $line );
    $month = $tmp[0];
    $day = $tmp[1];
    $time = $tmp[2];
    $numOfEntries = Count ( $tmp );
    $chapter = $tmp[$numOfEntries - 1];

    $title = '';
    for ( $i = 3; $i < $numOfEntries - 1; $i++ )
        $title .= $tmp[$i] . ' ';

    $title = Trim ( $title );

    $link = '<a href="/' . $title . '/' . $title . ' ' . $chapter . '">' . $title . ' ' . $chapter . '</a>';
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top