Note that there are some explanatory texts on larger screens.

plurals
  1. POglob - scan folder for php news article files
    primarykey
    data
    text
    <p>I have a news overview page, and a folder of php files I would like to individually include. Rather than manually including each one into my overview page, I thought I would use php to scan the folder for php files, and print them out as an include statement.</p> <p>I have the following code:</p> <pre><code>&lt;?php $articles = glob("/assets/news/form/*.php"); ?&gt; &lt;?php if(count($articles)) { natcasesort($articles); foreach($articles as $article) { ?&gt; &lt;?php include("$_SERVER[DOCUMENT_ROOT]/assets/news/overview/$article"); ?&gt; &lt;?php }} else { echo "Sorry, no articles to display!"; } ?&gt; </code></pre> <p>I get no syntax with this, but I do not receive any output. Just a blank space where the articles should be.</p> <p>The output I am wanting is something like this:</p> <pre><code>&lt;?php include("$_SERVER[DOCUMENT_ROOT]/assets/news/overview/1.php"); ?&gt; &lt;?php include("$_SERVER[DOCUMENT_ROOT]/assets/news/overview/2.php"); ?&gt; &lt;?php include("$_SERVER[DOCUMENT_ROOT]/assets/news/overview/3.php"); ?&gt; &lt;?php include("$_SERVER[DOCUMENT_ROOT]/assets/news/overview/4.php"); ?&gt; &lt;?php include("$_SERVER[DOCUMENT_ROOT]/assets/news/overview/5.php"); ?&gt; &lt;?php include("$_SERVER[DOCUMENT_ROOT]/assets/news/overview/6.php"); ?&gt; </code></pre> <p>Ultimately I am wanting to write a php function that scans a folder in <code>ROOT/assets/news/form/</code> for all php files, and include all the files with the same name from the folder <code>ROOT/assets/news/overview</code>.</p> <p>My news overview page is currently in <code>/news/index.php</code></p> <p>Can anyone help me out with this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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