Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to place output from an external php file to a specific place on the page
    text
    copied!<p>I have looked at other posts here regarding similar questions but cannot find an answer.</p> <p><strong>Edit</strong> I have been playing with this and I want to alter my question somewhat.</p> <p>I am having a problem placing the output that is echoed from an external php file.</p> <p>Here is some example code to demonstrate my problem - this is my main file <code>writephp.php</code>:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;Test Php &lt;/title&gt; &lt;link rel="stylesheet" href="writephp.css"&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="allContent"&gt; &lt;?php for($i=0; $i&lt;3; $i++): ?&gt; &lt;div class="commentBox"&gt; &lt;p&gt; Just a box&lt;/p&gt; &lt;/div&gt; &lt;?php endfor; ?&gt; &lt;a href="write.php?outputHtml"&gt;Php output&lt;/a&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Now I can center this with css:</p> <pre><code>.allContent { width: 400px; margin-left: auto; margin-right: auto; font-family: Arial; } .commentBox { border: 1px solid black; width: 400px; padding: 0px 5px 5px 5px; margin-top: 5px; } </code></pre> <p>So in the html file the php writes out boxes which are centered in the page since the php loop is within the "allConent" div.</p> <p>The anchor envokes an external php file which will echo some more boxes.</p> <p>That file looks like this and is called <code>write.php</code> (<code>writephp.php</code> is the main file this is called from):</p> <pre><code>&lt;?php if (isset($_GET['outputHtml'])) { echo "&lt;p class='allContent commentBox'&gt;" . "This is from external PHP" . "&lt;/p&gt;"; echo "&lt;p class='allContent commentBox'&gt;" . "This is also from external PHP" . "&lt;/p&gt;"; include 'writephp.php'; } </code></pre> <p><img src="https://i.stack.imgur.com/NOw7d.gif" alt="output looks like"></p> <p>But the echoed output from the external php is above the output from the main file -in fact it is placed before the <code>&lt;!doctype html&gt;</code> tag , obviously not good.</p> <p>the page source looks like this:</p> <pre><code>&lt;p class='commentBox allContent'&gt;This is from external PHP&lt;/p &gt;&lt;p class='allContent commentBox'&gt;This is also from external PHP&lt;/p&gt; &lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;Test Php &lt;/title&gt; &lt;link rel="stylesheet" href="writephp.css"&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="allContent"&gt; &lt;div class="commentBox"&gt; &lt;p&gt; Just a box&lt;/p&gt; &lt;/div&gt; &lt;div class="commentBox"&gt; &lt;p&gt; Just a box&lt;/p&gt; &lt;/div&gt; &lt;div class="commentBox"&gt; &lt;p&gt; Just a box&lt;/p&gt; &lt;/div&gt; &lt;a href="write.php?outputHtml"&gt;Php output&lt;/a&gt; &lt;/div&gt; &lt;/body&gt; </code></pre> <p></p> <p>In general my question would be "<strong>how do I place html coming from an external php file anywhere I want on the page?</strong> "</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload