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

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法