【发布时间】:2015-01-15 10:03:12
【问题描述】:
我必须为大学做一个 php 作业。
如果同一文件夹中有电影脚本文本和相同的图像,我将如何回显 html 文件的 15 行随机行?
到目前为止我所尝试的:
$folder = 'Filmnoir/';
$hitchcock ='Hitchcock/';
$shakespear ='Shakespear/';
$filetype = '*.*';
$files = glob($folder.$filetype);
$file2 = glob ($hitchcock.$filetype);
$file3 = glob ($shakespear.$filetype);
$count = count($files);
$count1 = count($file2);
$count2 = count($file3);
$scripttype ='*.html';
$Scripts = glob($ScriptFilmNoir.$scripttype);
$Scripts=file_get_contents("DoubleIndemnity.html");
if($_POST['radio1']=="0"){
if(($i %1)==0){
for ($i = 0; $i < $count; $i++)
{
echo '<div class="image2">';
echo '<img src="'.$files[$i].'" />';
echo '</div>';
if (condition) {
include 'DoubleIndemnity.html'; }
echo '</td></tr>';
}
echo '<div class="Passwordtext">';
echo 'Type in password to view full Script';
echo '</div>';
echo "<label><div class=\"password\"><input type='password' name='code' value='code'/></div></label>";
echo "<form method='POST' action='ca1_result.php'>";
echo "<div class=\"SubmitIt\"><input type='submit' name='submitScript' value='Submit Password'/></div>";
echo '</form>';
}
}
if($_POST['radio1']=="1"){
echo '<div class="Sorrytext">';
echo 'We apologize. No script available for this movie.';
echo '</div>';
}
if($_POST['radio1']=="2"){
echo '<div class="Sorrytext">';
echo 'We apologize. No script available for this movie.';
echo '</div>';
}
我想在同一个文件夹中有图像(例如DoubleIndemnity.png)和电影脚本(例如DoubleIndemnity.html)时实现这一点,我会得到 15 行随机的电影脚本文本和图像。我可以使用glob 函数吗?如果可以,我将如何实现?
我能问点别的吗?当我提交密码时,我如何获得完整的电影剧本?
我试过了:
foreach($files as $file2) {
if($_POST['submitPassword']){
if($file2 === '.' OR $file2 === '..' OR $file2 === 'thumbs.db' OR !is_dir($folder.'/'.$file2)) {continue;}
if(file_exists($folder.'/'.$file2.'/doubleindemnity.gif') AND file_exists($folder.'/'.$file2.'/DOUBLEINDEMNITY.htm')) {
echo '<div class="Container">';
echo "<div class='image2'><img src='$folder/$file/doubleindemnity.gif'>";
$lines4 = file($folder.'/'.$file2.'/DOUBLEINDEMNITY.htm');
$count = count($lines4);
for($a = 0;$a < $count;$a++) {
echo substr($lines4[$a],strlen($folder),strpos($lines4[$a], '.')-strlen($folder));
}
echo "</div>";
}
echo "</div>";
}
}
?>
使用该代码,我只需从 html 文件中获取几行代码。我不想要那个。我要全文。以及如何使用字符串替换功能摆脱代码,只接收段落中的文本?
干杯:)
【问题讨论】:
-
一定要用glob函数吗?您使用它有什么特别的原因吗?
标签: php