나는 PHP 웹 사이트에서 일하고 있으며 html 파일에서 임의의 15 줄을 반향시키고 싶습니다. 지금까지 나는 15 줄을 얻었다. 그러나 문제는 내가 HTML 파일에서 코드를 얻고 텍스트에서 15 줄의 줄을 얻지 못한다는 것이다. 올바른 해결책을 얻는 방식으로 내 코드를 작성하기 위해 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 변수를 정의 할 수는 없습니까? 그렇다면 어떻게해야합니까?
"블록 라인"을 정의 할 수 있습니까? –
블럭 라인이란 15 개의 라인 사이에 간격없이 텍스트를 의미합니다. – userSC