Compoot
Compoot

Reputation: 2377

call and display a text file from a php file

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

Upvotes: 0

Views: 170

Answers (1)

Johnny Dew
Johnny Dew

Reputation: 981

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>

Upvotes: 1

Related Questions