0

私のウェブサイトには、ユーザーが書いたタイトルとストーリーを含むストーリーのアップロード機能があります。ディレクトリにテキストファイルとしてアップロードします。PHPなどを使用してこれらのファイルのコンテンツを一覧表示する方法はありますか?また、ストーリーの200文字程度のみを表示し、[フルストーリーを表示]ボタンを使用してフルストーリーを表示したいと思います(これにはjQueryを使用します)。

これが私の現在のコードですが、それは機能せず、問題を理解することはできません:(

<head>
    <style type="text/css">header {font-size:20pt; color:#ff00e8;} footer {text-align: left; font-weight:bold; padding-left: 5px;} article {padding:20px;}</style>    
</head>
<body>
<h2><a href="../php/upload_story.php" style="font-size:15pt; color:#ff00e8; text-decoration: none;" id="tortenetfeltolt">Van  egy  jó  történeted? Írd meg és kikerülhet az oldalra!</a></h2>

<?php
$dataArray = array();
//Number of chars for the string
$num = 200;

//Check if DIR exists
if ($handle = opendir('../php/biralas_tortenetek/')) {
    //Loop over the directory
    while (false !== ($file = readdir($handle))) {
        //Strip out the . and .. files
        if ($file != "." && $entry != "..") {
           // $dataArray[] = array();
            //Store file contents
            $filecontent = file_get_contents($file);
            //Split the content and store in array
            $length = strlen($filecontent);
            $dataArray[] = array(substr($filecontent, 0, $num), substr($filecontent, $num, $length )); 

        }
    }
    //close the dir
    closedir($handle);
}


?>

<?php foreach($dataArray as $data) { ?>
    <div class="visible">
        <?php echo $data[0]; ?>
    </div> 
    <div class="hidden">
        <?php echo $data[1]; ?>
    </div>
<?php } ?>
</body>
4

1 に答える 1

2

私はあなたが使用したのを見ます:substr($ filecontent、$ num、$ length);

substr関数では、2番目の引数は開始する位置、3番目の引数は長さです。$ num = 200を指定したため、substrは位置200から開始します。

于 2012-07-03T15:05:37.977 に答える