Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Script To Build A List Of Links, from filenames and h3 tags
jlhaslip
post Feb 7 2006, 01:55 AM
Post #1


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 3,994
Joined: 24-July 05
From: In Trouble Again... still?
Member No.: 9,787
Spam Patrol



Another Unordered List Script

If you remember this Script, that tutorial was about creating an un-ordered list of links from a list of files contained in a Folder which was specifically named in the script. This current Tutorial goes several steps beyond that first Tutorial by being able to create a list from several folder names and, more importantly, the script reads the list of links from a 'flat file' rather than depending on the name of the folder to be hard coded in the script. It is only one small step to have the folder names found in a mysql table, but I'll leave that aspect up to someone else.

A sample is here


This script reads a list of folder names from a text file and then builds a list of links from the filenames. The script uses the contents of the first <h3> tag as the link description and the file-name as the anchor href. The file should be an html file.
This script may come in handy for creating a list of clickable links for use in sidebars and on 'sitemap' pages.

Simply store html files in folders grouped by topic, ensuring that the description inside the first h3 html tag of each file is suitable for using as the display field for the anchor list. The Folder name displays as a heading for the block of links.

This script is freely available for use by all who receive it.

Sample page using this script

CODE

<?php
print '<div id="sidebar">';
$folder_file ='flat_file_data.txt';     // name of flat file to read
$fp = fopen($folder_file,'r');        // open flat file for reading
if (!$fp) {print 'ERROR: Unable to open file'; echo '<br />';echo $folder_file;echo '<br />';exit;}// error if no handle found for flat file
$line= fread($fp,1024); // increase this length if required
$f_array=explode("\n",$line);
$folder_key=0;
//<!-- while loop start -->
while ($f_array[$folder_key]) {;
$fileCount = 0;
$p_folder=strip_tags(nl2br($f_array[$folder_key])); // for security
// print to begin un-ordered list using folder name as heading and as div id
print '<div id="'.$p_folder.'">';
print '<b>'.$p_folder.'</b>';
$folder = $p_folder.'/';
if ($handle = opendir($folder)) {
    while (false !== ($file = readdir($handle))) {
    if ($file != "." && $file != "..")  {
            $filename =$_SERVER['DOC_ROOT'].$folder.$file;
            $fp = fopen($filename, "r");
            $contents = fread($fp, filesize($filename));
            $pos1 = strpos($contents,"<h3>");
            $pos2 = strpos($contents,"</h3>");
            $str_length =  $pos2 - $pos1;
            $title = substr($contents,$pos1+4,$str_length-4);
            $title_array[] = $title;
            fclose($fp);
            $file_array[]= $file;
            $fileCount++;
            }         } } closedir($handle);
if ($fileCount > 0) {
           $iterator = 0;
           while($title_array[$iterator])  {
           $file = substr($file_array[$iterator], 0, (strlen($file_array[$iterator])));
                 print '<li><a href="'.$folder.$file.'">'.$title_array[$iterator].'</a></li>';
               $iterator ++;  }  
unset($file_array);
unset($title_array); }
print '</div>';
$folder_key++;
}  
//-- end while loop -->
//fclose($fp);  // close flat file
print '</div>';
  ?>


Sample File Contents:

HTML
<head></head>
<title></title>
<body>
<h3>An article name</h3>
</body>


Sample Flat File Contents:

QUOTE

artfold
artfold1
artfold2
...
artfoldn

Enjoy.

Go to the top of the page
 
+Quote Post
rvalkass
post Feb 7 2006, 06:51 AM
Post #2


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,114
Joined: 28-May 05
From: Hertfordshire, England
Member No.: 7,593
Spam Patrol



Excellent script. I was going to write something like this myself for a website, but you've already done it, thanks smile.gif
Go to the top of the page
 
+Quote Post
tuddy
post Feb 7 2006, 01:10 PM
Post #3


Privileged Member
*********

Group: Members
Posts: 570
Joined: 5-July 05
From: Ballarat
Member No.: 9,042



You've Done it again jlhaslip, nice and simple. I've been looking for something like that, and you played it right into my hands. Thanks!...

Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Free Classified Ads--no Hype(4)
  2. Web Surfing- Script Needed(2)
  3. Delay X Seconds In Flash(1)
  4. Verifying Email Addresses(9)
  5. Meta Tags(7)
  6. Watermark Your Image With Simple Php Script(35)
  7. Make Money Clicking On Links(8)
  8. Free Sms Site(5)
  9. Tutorial Build Your Own Cs Server 1.6 Steam(14)
  10. Data Structures -- Linked List(8)
  11. Data Structures -- Linked List -- Reverse(4)
  12. Php Downloads Script(4)
  13. How Often Do You Use Css?(12)
  14. Photoshop, Flash And Fireworks Tutorial Site Links(2)
  15. Build A Website(12)
  1. Guessing Php Script(2)
  2. Database Or Pdf(3)
  3. Php Guest Online Script(3)
  4. How To Make Php Newsletter Script(3)
  5. Ameran Portals?(1)
  6. Build Your Own Asp.net Website Using C# & Vb.net Review(0)
  7. Java And Xml: Links You Must Have(1)
  8. List Of Free Games(9)
  9. Top 10 Geek Ways To Beat Boredom(12)
  10. Browser Compatibility Problem With Firefox - Javascript + Css(3)
  11. Seeking Help With Javascript(1)
  12. Idea For Using A Cron Job To Grab Daily Travian Map.sql Updates(3)
  13. Good Freeware List(3)


 



- Lo-Fi Version Time is now: 6th September 2008 - 07:52 PM