Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I create a menu in PHP from files in a directory
    primarykey
    data
    text
    <p>I'm very new to PHP and would like some help creating a menu from files contained in a directory. As I add files i'd like the menu to automatically add an item.</p> <p>The files in the directory are .htm files and the naming convention is year, then month separated by an underscore i.e, 2013_6.htm (June 2013)</p> <p>I would like to be able to read the files and then create a menu from those.</p> <p>I have managed to create a sorted array of the files, like this (which works fine):</p> <pre><code>$dir = "$cal_path"; $dh = opendir($dir); while (false !== ($filename = readdir($dh))) { if ($filename != "." &amp;&amp; $filename != ".."){ $files[] = $filename; } } sort($files); </code></pre> <p>How do I now get this array of files into a menu item list that I can then style with CSS, something like this, where xxxx is the year from the filename and yy is the month from the file name.</p> <pre><code>$cal_menu = &lt;ul&gt; &lt;li&gt;&lt;a href="$base_url/calendar_view?year=xxxx&amp;month=yy"&gt;June 2013&lt;/a&gt;&lt;/li&gt; &lt;li&gt;etc&lt;/li&gt; &lt;li&gt;etc&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>I created an array of months and corresponding month names</p> <pre><code>$CalendarMonth = array("1"=&gt;"January","2"=&gt;"February","3"=&gt;"March","4"=&gt;"April","5"=&gt;"May","6"=&gt;"June","7"=&gt;"July","8"=&gt;"August","9"=&gt;"September","10"=&gt;"October","11"=&gt;"November","12"=&gt;"December"); </code></pre> <p>I hope I have explained my problem properly. Many thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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