duanguanya3052 2017-09-16 15:08
浏览 86
已采纳

从php文件中调用并显示文本文件

I have the following php file which displays this webpage Screenshot of displayed webpage Everything inside the black box is from a text file called questions.txt, that is called from the php file with the below code:

I wish to call and display (in the same format, like a black bordered box) some introductory text with images and possible iframes like youtube videos) just before the questions.

In the code below I've included it as a comment # ...have tried various things but it hasn't worked.

The file needs to be called and displayed under "Test your Knowledge" and above the start of the questions.

<!-- 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>

Can someone please include in my original code an explanation and fix for how to call and display a text file (or another php file) inside this one, in the position desired.

I'd also like to format the text of the questions to make them left-aligned (have posted that in another question)

I have tried various things but they haven't worked:

1. include('questiontrinket.php') (I included it as below) but it just showed up as plain text rather than rendering the file

<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') ?>

...didn't work

2. I also tried the following

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

This didn't work either

  • 写回答

1条回答 默认 最新

  • duanben4771 2017-09-16 15:48
    关注

    The following code works fine for me

    <!-- 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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog