2017-09-16 29 views
0

我有顯示此網頁的黑盒子裏面 Screenshot of displayed webpage 一切都是從名爲questions.txt一個文本文件,下面的php文件,即從與PHP文件名爲顯示文本文件下面的代碼:通話,然後從一個PHP文件

我希望在問題出現之前調用並顯示(使用與黑色邊界框相同的格式)一些包含圖像和可能的iframe的介紹性文本)。

在下面的代碼中,我已經將它作爲註釋#...嘗試了各種各樣的東西,但它沒有奏效。

該文件需要在「測試您的知識」下面和問題開頭的上方進行調用和顯示。

<!-- Main 
============================================= --> 
<section id="code"> 
    <div class="container-fluid" style="text-align:center;"> 

     <p></br></br></br></br></p> 

     <div class="row"> 
     <div class="col-lg-2 text-left"> 
      <p></br></br></br></br></p> 

      <?php include 'quiz-sidebar.php'; ?> 
     </div> 
     <div class="col-lg-10 text-center"> 

     <h2 class="section-heading" style="color:black;">Test Your Knowledge : <?php include "content/quiz/". $_GET['quiz'] ."/title.txt"; ?></h2> 
     <p></br></p> 

     #I want to call and display a txt file here (called introtext.txt), in the same format as below, but just as text 

     <div style="border-style: solid; border-radius: 5px; border-width: 5px;"> 
      <p></p> 
     <form method="POST" action="<?php echo "quiz-result.php?quiz=".$_GET['quiz']; ?>"> 

      <?php 

       $loadedQuestions = readQuestions("content/quiz/". $_GET['quiz'] ."/questions.txt"); 

       displayTheQuestions($loadedQuestions); 

      ?> 

      <input type="submit" name="submitquiz" value="Submit Quiz"/> 



      </form> 
      <p></p> 
     </div> 

      <p></br></br></br></br></p> 
     </div></div> 

    </div> 
</section> 

可有人請我的原代碼,包括一個解釋並解決了如何調用和顯示這個裏面一個文本文件(或其他PHP文件),在需要的位置。

我也想格式化的問題文本,使其左對齊(已經張貼在另一個問題)

我曾嘗試過各種東西,但他們都沒有奏效:

1.包括(「questiontrinket.php」)(我把它作爲下文),但它只是出現了以純文本格式,而不是渲染文件

<h2 class="section-heading" style="color:black;">Test Your Knowledge : <?php include "content/quiz/". $_GET['quiz'] ."/title.txt"; ?></h2> 
      <p></br></p> 

      <?php include('introtext.php') ?> 

...沒有工作

2.我也試過以下

<?php 
    echo file_get_contents("introtext.php"); // get the contents, and echo it out. 
    ?> 

這並沒有工作,要麼

+0

爲什麼不把它叫做'introtext.php '然後你可以簡單地將'include('introtext.php')' –

+0

作爲一個完整的初學者來做php,你可以把它作爲一個答案,在現有的代碼裏面,所以我知道它應該放在哪裏以及如何放置它。我已經嘗試了以及<?php echo file_get_contents(「questiontrinket.php」); //獲取內容並將其回顯出來。 ?>但它提出了一個錯誤 – MissComputing

+0

請參閱我已經嘗試過的兩件事情的更新不幸的是,不幸的是 – MissComputing

回答

1

下面的代碼工作正常,我

<!-- Main 
============================================= --> 
<section id="code"> 
    <div class="container-fluid" style="text-align:center;"> 
     <p><br><br><br><br></p> 
     <div class="row"> 
      <div class="col-lg-2 text-left"> 
       <p><br><br><br><br></p> 

       <?php include 'quiz-sidebar.php'; ?> 
      </div> 
      <div class="col-lg-10 text-center"> 

       <h2 class="section-heading" style="color:black;">Test Your Knowledge : <?php include "content/quiz/". $_GET['quiz'] ."/title.txt"; ?></h2> 
       <p><br></p> 

       <!-- I want to call and display a txt file here (called introtext.txt), in the same format as below, but just as text --> 
       <?php include 'introtext.php'; ?> 

       <div style="border-style: solid; border-radius: 5px; border-width: 5px;"> 
        <p></p> 
        <form method="POST" action="<?php echo "quiz-result.php?quiz=".$_GET['quiz']; ?>"> 
         <?php 
         $loadedQuestions = readQuestions("content/quiz/". $_GET['quiz'] ."/questions.txt"); 
         displayTheQuestions($loadedQuestions); 
         ?> 
         <input type="submit" name="submitquiz" value="Submit Quiz"/> 
        </form> 
        <p></p> 
       </div> 

       <p><br><br><br><br></p> 
      </div> 
     </div> 
    </div> 
</section> 
+0

這實際上取決於你渲染圖像的意思。如果您想要顯示服務器上文件的圖像,只需在introtext.php文件「image'中添加一個img標籤。如果你想插入YouTube視頻,你可以用'iframe'做同樣的事情。只要將你的外部文件看作是一個自己的php頁面。您只是將代碼分離到另一個文件中,但最終結果全部顯示在同一頁面上。 –

相關問題