0

私は PHP Web サイトで作業しており、html ファイルからランダムな 15 行をエコーし​​たいと考えています。これまでのところ、15行しかありませんが、問題は、テキストから15ブロック行ではなく、htmlファイルからコードを取得することです。2 つの変数 $pathinfo と $random を定義して、正しい解決策を得る方法でコードを記述するにはどうすればよいでしょうか?

私のコード:

      <?php  

        $selected_file = $_POST['radio1'];
        // get the filename of the file
        $fileinfo = pathinfo($selected_file);
        $filename = $fileinfo['dirname'] . DIRECTORY_SEPARATOR . $fileinfo['filename'];
        $password = 'code';




    if (isset($_POST['submitradio']))
    { 
         echo '<div class="imageselected">';
         echo '<img src="'.$selected_file.'" /></br>'.PHP_EOL;
         echo '</div>';
        // check to see if a html file named the same also exists
        if(file_exists("$filename.html"))
        {

            echo "<form action='test_result.php' method='post'>";
            echo '<div class="Password">';
            echo 'Type in password to view full Script';

            echo "<label><div class=\"Input\"><input type='password' name='passIT' value='passit'/></div>";
            echo "<input type='submit' name='submitPasswordIT' value='Submit Password'/></div>";
            echo '</div>';
            echo '</form>';
            echo "$filename.html shares the same name as $selected_file";



        $splitTag = "[[mylinebreak]]";
        $html = file_get_contents("$filename.html");
        $newcontent = stri_replace("</div>", $splitTag, $html);
        $newcontent = stri_replace("<br>", $splitTag, $newcontent);
        $newcontent = stri_replace("</h1>", $splitTag, $newcontent);
        $newcontent = stri_replace("</h2>", $splitTag, $newcontent);
        $newcontent = stri_replace("</h3>", $splitTag, $newcontent);
        $newcontent = stri_replace("</h4>", $splitTag, $newcontent);
        $newcontent = stri_replace("</h5>", $splitTag, $newcontent);
        $newcontent = stri_replace("</h6>", $splitTag, $newcontent);
/* and so on ... */
        $newContent = strip_tags($newContent);
        $lines = explode($splitTag);

        for($x = 1;$x<=15;$x++) {

        echo $lines [rand(0, count($lines)-1)]."<br>";
        }

            // end of forloop

            }
            // end of check
              // start Sorrytext

                else
                {
                 echo '<div class="NoScript">';

                    echo "We apologize. No Script available for this movie.";
                    echo '</div>';
                }

             // end Sorrytext
    }
    // End of submitradio
    if($_POST['submitPasswordIT']){
    if ($_POST['passIT']== $password ){
    echo "You entered correct password";
    $dirs = glob("*", GLOB_ONLYDIR);
    $pathinfo = ($dirs.'/'.$lines.'/html');
    include($pathinfo);
    }
    else{
    echo "You entered wrong password";
    }
    }

    ?>

助けていただければ幸いです:)

やあ。

私はあなたの解決策を試しましたが、うまくいきませんでした。私はそれから何も得ません。別の解決策を考えていただけますか?$random 変数を定義するだけでなく、はいの場合はどうすればよいですか?

4

1 に答える 1