call and display a text file from a php file - php

I have the following php file which displays this 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

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>

Related

PHP conditions and loops are breaking html formatting

I'm trying to convert my html template into a php script that simply takes returned database values and uses comparisons on certain values to place the correct content in the placeholders.
The data is being returned properly and is showing on the page but my html formatting is breaking.
This should output a very simple format of a container row, 2 half-width columns each of which with its own internal div like this:
<div class="row middle">
<div class="col-lg-6 leftFifty">
<div class="leftContent" style="background-color: white; height: 100%; ">
Content
</div>
</div>
<div class="col-lg-6 rightFifty">
<div class="rightContent" style="background-color: white; height: 100%; ">
Content
</div>
</div>
</div>
But when I add in the PHP conditions it breaks the format completely including anything included after this section
<div class="row middle">
<?php foreach($panelResult as $PR): ?>
<div class="col-lg-6 leftFifty">
<?php if($PR['panel_type_id'] == 2){ ?>
<div class="leftContent" style="background-color: white; height: 100%; ">
<?php echo $PR['content']?>
</div>
</div>
<div class="col-lg-6 rightFifty">
<?php } elseif($PR['panel_type_id'] == 3){?>
<div class="rightContent" style="background-color: white; height: 100%; ">
<?php echo $PR['content'] ?>
</div>
<?php } ?>
</div>
<?php endforeach; ?>
</div>
<!--This div is not showing-->
<div class="row bottom">
<div class="col-lg-12">
<div class="marquee"><h2>This is a test</h2></div>
</div>
</div>
For this page type, row-middle should exist, and both the leftFifty/leftContent class as well as the rightFifty and rightContent class should all exist.
The only reason I'm using the If statement is to make sure that the panel_type_id ==2 content fills the left div, and same for the right div if it equals 3.
How can I restructure this to retain the html formatting?

Inheriting files in specific div through php files

I've created a file called menu.php to be my universal nav/menu file. The way it was created using bootstrap though, I have a div called article at the bottom which serves as the main body of the app, since the sidebar in my menu is expandable/responsive.
I really want to have one global menu file. I'm currently including it in all of my content pages like so:
<?php include("menu.php")?>
This works but it breaks my formatting. What I'm trying to do is make all of my main pages such as index.php have the html formatted so that it will always sit inside the tag in my code below which shows card classes.
<header>
<div class="branding">
<div class="menu-button menu-toggle nav">
<i class="material-icons">menu</i>
</div>
<img src="" />
</div>
<div class="page-details">
</div>
<div class="settings">
<div class="menu-button profile">
<i class="far fa-user-circle fa-2x"></i>
</div>
<div class="menu-button menu-toggle aside">
<i class="material-icons">chat</i>
</div>
</div>
</header>
<div class="app">
<nav>
<div class="title-block">
<img src="" />
</div>
<ul>
<li><a href="#"><i class="material-icons">home</i>
<span>Home</span></a></li>
</ul>
</nav>
<!--This following article section is the main body of the page, that I want each additional page to take up-->
<article>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
</article>
</div>
Example:
Menu.php is my global menu/nav file but it makes the page/app act as a wrapper for all the other pages (index.php, editor.php, etc.)
menu.php
<div class="app">
<nav>
Nav menu content
</nav>
<article>
This will be the main page article for index.php, editor.php,etc.
</article>
</div>
example with index.php (the start and end are just hypothetical to show the endpoints)
<body>
<?php include("menu.php");?>
<?php start('article') ?>
<!--Everything from here to the end() call would be inserted in the article tags on menu.php-->
<div class="app">
<div id="content">
<div>
<h1 style="text-align: center; color: #A9BD50; ">Content Management Editor</h1>
</div>
<form method="post">
<textarea id="mytextarea"></textarea>
</form>
<div>
<h1 style="text-align: center; color: #A9BD50; ">Preview</h1>
</div>
</div>
</div>
<?php end() ?>
</body>

Specific formatting to insert generic margin with css inside php file

I have the following code and displayed output on a webpage shown below...
...and wish to create a slight indent in the margin so that the left align is not so severely on the left? The result is generated from two text files, so it is the main code that generates the css
It appears to be this line that generates the left as opposed to centre command;
<div class="col-lg-10 text-left">
The whole code snippet in question is here:
<!-- Main
============================================= -->
<section id="code">
<div class="container-fluid" style="text-align:left;">
<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-left">
<h2 class="section-heading" style="color:black;">Test Your Knowledge : <?php include "content/quiz/". $_GET['quiz'] ."/title.txt"; ?></h2>
<p></br></p>
<div style="border-style: solid; border-radius: 5px; border-width: 5px;">
<?php include "content/quiz/". $_GET['quiz'] ."/questiontrinket.php"; ?>
</div>
What do I need to add to the existing code to get the margins to be rendered correctly (i.e with an indent for both the intro text (questiontrinket.php) and the questions held in question.txt?
Edit: deleted previous answer since he needs a copy paste solution.
Here goes:
<!-- Main
============================================= -->
<section id="code">
<div class="container-fluid" style="text-align:left;">
<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-left">
<h2 class="section-heading" style="color:black;">Test Your Knowledge : <?php include "content/quiz/". $_GET['quiz'] ."/title.txt"; ?></h2>
<p></br></p>
<div style="border-style: solid; border-radius: 5px; border-width: 5px;">
<div class="questions" style="display:block; padding-left: 10px;">
<style>
.questions input[type="radio"]{
margin-left: 5px;
}
</style>
<?php include "content/quiz/". $_GET['quiz'] ."/questiontrinket.php"; ?>
</div>
</div>

My php page will display my html header include in the dreamweaver preview but not in a browser

The snippet of include code in my php file looks like this.
<div id="header">
<!--#include virtual="includes/frontpage_header.html" -->
</div>
And my frontpage_header.html code looks like this.
<div style="float: left; width: 30%;"><img id="headerlogo" src="../images/DynamicHomes45th.png" alt="Dynamic Homes Logo"/>
</div>
<div style="float: left; width: 33%;">
<h1>QUALITY CUSTOM BUILT HOMES</h1>
</div>
<div style="float: right; width: 33%;">
<div id="headernav">
<div id="whybuild">
<h2>WHY BUILD DYNAMIC</h2>
<img src="../images/whybuildicon.png" alt=""/> </div>
<div id="gallery">
<h2>GALLERY</h2>
<img src="../images/galleryicon.png" width="43" height="43" alt=""/>
</div>
</div>
</div>
Like I said in the title, it will display in my dreamweaver's design view, but not in a browser. I'm not sure what's wrong.
Try including it like this using Php:
<div id="header">
<?php include("includes/frontpage_header.html"); ?>
</div>
Also it's worth making this frontpage_header file a .php rather than .html considering you are using Php elsewhere in your project.

can't include the .php file properly

I am trying to include different php files in the index.php file
on my webpage
http://www.e-lang.de/index.php
but the contents are included as simple text. What I want is that they should be proper DOM elements not the text.
here is my index.php
<div class="container">
<div class="navbar mt10">
<div class="navbar-inner">
اردو ایڈیٹر
<ul class="nav">
<li class="active">صفحۂ اول</li>
<li>رابطہ</li>
</ul>
</div>
</div>
<?php include_once "editor.php"; ?>
<!-- hidden inline form -->
<?php include_once "emailform.html"; ?>
</div>
and editor.php looks like
<div class="well widget">
<div class="widget-header">
<h3 class="title">اُردوھے جس کا نام</h3>
</div>
<div class="row">
<div class="span7">
<form method="post" action="save.php" id="text-container">
<input type="hidden" name="save" value="0" id="savetext">
<textarea rows="22" id="text-urdu" name="text" class="span7" dir="rtl" style="font: normal 25px Arial"></textarea>
</form>
<div class="rel">
<div id="counter"></div>
</div>
</div>
<div class="span4" id="help-wrapper">
</div>
</div>
<div class="row">
<div class="span11">
<div class="well widget" id="buttons-listing">
<ul class="listing">
<li>Print</li>
<li>Save</li>
<li>pdf</li>
<li></li>
<li><a href="#" class="button" id="btn_email" >E-Mail</a></li>
</ul>
</div>
</div>
</div>
</div>
There is no actual PHP in editor.php. Please remove the first line (containing the PHP open tag, <?php) from the editor.php file, as that should only surround PHP code. For standard HTML, you don't need to use the <?php tag.

Categories