Nov 8, 2009

Building An Unordered List Of Anchors - From a list of files in a folder

free web hosting
Open Discussion > MODERATED AREA > Tutorials

Building An Unordered List Of Anchors - From a list of files in a folder

jlhaslip
Building an Unordered List of Anchors from a Folder of files

This script reads files from the named folder and then builds a list of links from the filenames using the contents of the first <h3> tag as the link description and the file-name as the anchor href. The file should be a web readable file such as html or php.
This script may come in handy for creating a list of clickable links for use in sidebars and on 'sitemap' pages.

Simply build a series of html files and store them all in a single folder, ensuring that the description inside the first h3 html tag is suitable for using as the display field for the anchor list. The Folder name you use must be altered in this script to match your folder name, of course.
This script could be used to generate a list of links in sidebars or on sitemaps. Be creative.
This script is freely available for use by all who recive it.

Sample page using this script

(php coding based on a script supplied by Tyssen)(Thank you Tyssen)

CODE

<?php
$fileCount = 0;
$folder = "folder-name-here/"; // change the folder to your folder name
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>");// look for the h3 tag position
$pos2 = strpos($contents,"</h3>");// look for the ending h3 position
$str_length =  $pos2 - $pos1;// calculate the length between tag positions
$title = substr($contents,$pos1+4,$str_length-4);// create a string based on tag position and offset
$title_array[] = $title;
fclose($fp);
$file_array[] = $file;
$fileCount++;
}
}
}
closedir($handle);
if ($fileCount > 1) {
print "<ul>\n";// start ul tag
$iterator = 0;
// this section prints the li tags, use css to define the attributes of the ul
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 ++;
print "\n\n";
}
print "</ul>\n";
unset($file_array);
unset($title_array);
}
?>


Sample File Contents:

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


Sample page using this script

I hope you find this useful. I may spend some more time on this and make a few modifications. If I do, I will post them here.


 

 

 


Comment/Reply (w/o sign-up)

darkvirus
greate tutorial dude i'm kinda new to php this will help

Comment/Reply (w/o sign-up)

truefusion
I think some of the coding could be removed, and instead of a while loop, maybe a foreach statement would have been a better choice.

Comment/Reply (w/o sign-up)

Tyssen
QUOTE(jlhaslip @ Jan 12 2006, 10:14 AM)
(php coding based on a script supplied by Tyssen)(Thank you Tyssen)

Well, I got the bulk of it from someone else on another forum, so I can't really take credit for it. wink.gif

Comment/Reply (w/o sign-up)

matak
EDIT: Just a comment on how this is great post.. Couse i can't delete my entry

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : building, unordered, list, anchors, list, files, folder

  1. Deny Or Grant Users Access To Files Of Choice (vista)
    Uses Bat Files To Deny Or Grant People Access To Files (3)
  2. Locking A Folder With No Software At All!
    works on XP AND VISTA!!! (4)
    I know that there may be some tutorials like this in the web, but I made this one a very long time
    ago /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />. Simple
    Copy-Paste-Rename-Store-and LOCK. can work anywhere on any computer. NO Software Required.
    Simple Lock your Folder, with these Few Steps. Ive tried it, and works great. Ive only tried it on
    Windows Xp, SP2. IM not sure, if it works on other OS as well. but its harmless, so try it out.
    Steps: 1- make a new folder ( name it as you like ) 2- inside this folder make a ( T....
  3. How To Create Pdf Files Using Free Tool
    Introduction to use a free tool to create PDF file (10)
    Now, that you don't need to have expensive software like Acrobat to create PDF. All you need is
    Microsoft Office and a software name doPDF. You can download the freeware from
    http://www.dopdf.com/download.php After downloading dopdf.exe, follow the instruction below 1.
    Double click to install it, as display at image 1.jpg, choose a language and click OK 2. You will
    see 2.jpg click next 3. Click I accept the agreement see 3.jpg, click next 4. Now you will see
    4.jpg, select the folder to install it and click next 5. When seeing 5.jpg, This is the folder group
    in Star....
  4. Clearing Your Ie Tif
    Clear your Temporary Internet Files on IE (0)
    -Welcome to: Clearing your Internet Explorer Temporary Internet Files Tutorial-!
    Attention!: As some of the members on here may know, it is possible to clear your Internet Explorer
    Temporary Files. I have searched this entire Tutorials subforum to find a topic already made, and I
    have found nothing. This tutorial I did NOT find this on Google, or any other search engine. I
    always find this out for myself. Lets start: Ok, first we open up Internet Explorer, then we
    click "Tools"...then we click on "Internet Options...". On the Main page "General" we l....
  5. How To Download Any Flv Files From Any Sites
    (7)
    Now you can download any flv files from any websites!! People often know how to download youtubes
    clip, but not from other sites. In this tutorial you will need a tool name Moyea FLV Downloader, it
    is free and you can download it at http://www.flvsoft.com/download_flv/ This is the best tool i
    have meet up with to download flv files in any site. Since it can detect flv files, and list it, you
    can download it as you want, so no more favourite clips goes away from your sight and now you have
    it on your own hard drive! 1. Run moyea flv downloader see 1.jpg 2. At the left....
  6. Folder View In Kde 4.1
    (4)
    Even though there was a lot of negative criticism over the new KDE, but over the last time there are
    mostly positive critics and they encouraged me to try this DE (some of them even told me that KDE4
    is better than MS Vista's and even OSX's one!). For those which don't know what is KDE
    and what should they expect from it, here is the official link from the devs. :
    http://www.kde.org/announcements/4.1/ With the comming of KDE 4 lots of things changed and lots
    of new things were added in it, but I'll keep on one productive thing in here, and its called ....
  7. Debug Exe Files
    How to debug an exe file. (4)
    Think that we have written a program, and some codes are wrong. We can go back to compiler and
    change the code, and compile again. But I will show you how to correct our mistakes without using
    the compiler. Let's start: I have written a program in Delphi. Let's see my mistake. I
    have created a form like this. After this I wrote the codes in the Compare Button click as
    below. CODE 1.   procedure TForm1.ComparebuttonClick(Sender: TObject); 2.   var 3.    
    a,b:integer; 4.   begin 5.     a := StrToInt(EditA.Text); 6.     b := StrToInt(EditB.Text); 7. 8.  ....
  8. Tutorial : Hide Folder Without Any Softwares
    Descriptive enough! (17)
    It's easy, just a few steps and your folder will be hidden First step : Create folder, name it
    using alt+0160 Second : A folder will be created with name 1 space, then right click the folder,
    properties, customize, change icon, see for a blank icon and press apply Enjoy Video tutorial
    uploaded by me http://www.youtube.com/watch?v=EW8dD3KeUJk Have fun.....
  9. Download Files Off Esnips.com
    even now that the download button is gone! (0)
    hey everyone, i am sure that many of you may have heard of esnips , which is basically online file
    storage/sharing. you can now find almost any file imaginable on esnips, and in many ways it is
    better than rapidshare. previously, once you are signed in to esnips, you were able to download any
    esnips file via a button only viewable to members. back then, there was a method to download any
    file without even signing in. then, probably due to legal issues, users were able to choose whether
    or not people could download their files. the hack mentioned above, though, still....
  10. Cakephp On Ubuntu
    using your own public_html folder (1)
    Hi, there are many tutorials about this, but i would like to type the steps i followed in order to
    get cakephp working on my user public_html folder. as many of you probably know, if you have
    apache's userdir module loaded, you can put your web pages on /home/user/public_html , and
    access them with the url: http://localhost/~user/ . I really prefer this, so all my web pages are
    on my personal home, but how to configure cakephp to work with these paths, i got a hard time with
    this, but finally got it!. here's how: in case you don't have apache2's userd....
  11. How To Hide Your Important Files And Folders
    In Ms. Windows, Without Using Programmes. (7)
    Most of people share their computers with others -family, mates, buddy or whoever- and that sharing
    threatens their secrets and private file to be revealed, letting some people to know things they
    shouldn't know.. My Securing Way: Operation - Camouflage Use an Icon
    Editor to generate a 1x1 Transparent Icon and Save it .. > 1 Open CMD.. Start >> Run or Press
    WindowsLogo+R.. Lets Say you wanna hide a Folder named " secure " and it's located in
    E:\folder\ so Write E: and Press Enter then Write Cd folder and Enter then Attrib +s +h....
  12. How To Better Compress Files In Winrar
    (7)
    How to better compress files in winrar As you know Winrar is more popular and powerful than
    other compressor softwares. To better compress your files and folders follow below steps: 1- Right
    click on your file and select "Add to archive…" from context menu. A dialog box will appear. 2- In
    General tab and in "Compression Method" dropdown menu, select "Best". 3- Click on Advanced tab and
    then click on "Compression" botton. Advanced Compression Parameters dialog box will appear. 4- In
    Text Compression section select Force and in Prediction Order type 63 and in Memory....
  13. Cpanel Analysis And Log Files
    Part 4 of My 7 Part Tutorial (0)
    This Tutorial will be divided into 7 different parts, and this is the first part, when i get the
    other parts together, i will post the links under here /biggrin.gif" style="vertical-align:middle"
    emoid=":D" border="0" alt="biggrin.gif" /> Enjoy. Part 1: E-mail Management Part 2: Useful Site
    Management Tools Part 3: Useful Site Management Tools2.1 Part 5: Advanced Tools Part 6:
    PreInstalled Scripts, Extras, and Cpanel Options Part 7: Fantastico Detailed Cpanel Tutorial
    Part 3: Analysis and Log Files In this tutorial I will, in detail explain all ....
  14. Dynamic Signatures - The Real Way To Go
    Forget placing index.php in a signature.png folder. (8)
    This is only a very quick tutorial, meant to complement the dynamic signature tutorials that already
    exist here. It's nothing new, but it was just brought to my attention that not many people seem
    to be aware of this method. This does not cover the actual creation of dynamic signatures, per se -
    but rather a better 'trick' to allow you to use dynamic signatures on forums such as this
    one. I've noticed that most of the dynamic signature tutorials on this forum state that you
    must place a file index.php in a folder .png, in order to trick Invision Power....
  15. How To Fix Problems With Shareaza
    ONLY for people to download LEGAL files with. (1)
    Can't run shareaza and surf the internet at the same time? There could be two
    problems: Your uploads are killing your downloads and/or you are using Windows 95/98/ME. If you
    are uploading constantly and havent limited the bandwidth then it is likely that you are killing
    your download speed which is affecting your ability to surf the web and do other tasks. If you
    are uploading lots and download speeds are suffering: Start Shareaza. Click on the Tools menu,
    then click Shareaza Settings. In the box that just popped up, there is a list of men....
  16. How To Chmod Files
    (16)
    This is a short but useful tutorial on how to chmod files I offen find wap/web masters
    uploading scripts into their severs,creating databases,confirming scripts to work with the databases
    etc. but little you know that some people dont know how to chmod files.know how can you become a
    good wap/web master without knowing the important basics? Never the less this tutorial will guide
    and teach you how to chmod files and the importance it has. How many times have you uploaded a
    script/file and did everything right but you still getting errors,or you not being able to ....
  17. How To Create Self-unzipping Files
    for beginners (18)
    This tutorial is based on winzip 10.0 (but it should work on other versions). Create or open the
    file you would like unzipped. Now, on the Actions menu, click make .exe file. A popup box should
    popup. Click ok. Now in the popup box that appears, type in the default folder that the program
    will unzip to. Press ok. Now another popup will tell you if you want to test the file, click yes.
    Now click ok again in the box that appears. Now press unzip. If it says - files unzipped
    succsessfully! Click ok and pat your self on the back! You have created the self-zipping ....
  18. How To Open Bam & Tt Files, long 3 part tutorial
    (2)
    Part 1 Extracting files PLEASE DO NOT COPY ! This links with my other topic to 5.6 bams ,
    Loads of people have asked me how do you get pview , extract .mf files. Well im going to show you
    all in one. 1. Download Panda3D v.1.1.0 from here Start Picture Totorial Again, ugggh
    ! 1. Navigate your way to where you installed Panda3D ( It is usually : C:\Panda3D-1.1.0 )
    2. Open the bin folder in the Panda3d directory 3. Find and copy Multify.exe and PView.exe
    4. Paste the Files to the desktop 5. Navigate your way to C:\Documents and s....
  19. Building An Address Book With Java
    (1)
    Dear Friends I am sharing a java program with all of u which I built a few years back. I guess it
    will help beginners. It uses java utill package to store data in a flat file. The File
    Name-----phone.java import java .io .*; import java .util .*; import java.awt.event.*; public
    class phone { public void new_record() { String id,name,city,add,number,total,list;
    boolean bln=false; try { Properties pr=new Properties(); FileInputStream
    fin=new FileInputStream("phone.dat"); if(fin!=null) { pr.load(fin); } ....
  20. Php Script To Make A Link List
    From the list of the Directory Files (6)
    Well, it has been a while since I have added anything to the Tutorial Sectiion, so here is another
    script for the members to enjoy. This one creates a list of links from the contents of the directory
    which it is run from. For instance, if you run it from the public_html folder, then all the files
    (not the Directores) are listed and linked so when you click on the link, that file is parsed and
    output to the browser. Here is the code: "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    An XHTML 1.0 Strict Page to List the files in this directory ....
  21. Templating System Using Php Includes
    Building a Dynamic site using Includes and flat-files. (13)
    Php based Templating System http://jlhaslip.trap17.com/template/index.php The Source Code
    for the scripts are included (literally) on the different pages on the Demo, including the Contact /
    Email script. The only page not there yet is the Message Script. Maybe tonight I will upload that.
    This one uses a little bit of query-string checking to confirm that the contents of the page are
    actually available (file_exists())and an allowed page content before serving it up. The
    'allowed page content' is done by checking against a flat-file containing an array....
  22. How To Create Html Page Anchors
    Click A Link And Take You To A Certin Place On The Same Page (5)
    Have you ever wondered how people have a normal link but all it does it take you to the middle of a
    long page? well here is a solution DEMO: Here Ok well first off for the link it will be just
    like a normal link code except you wont put a http://URL.com/file.php it will look somthing like
    this QUOTE name ">Click This Link! there must be a # sign in front of this to work.. now,
    for the content that the person will be re-directed to after clicking the link QUOTE name ">
    the items in bold is what you need to change QUOTE name "> if yo....
  23. How To Clear Your Temp Files
    (17)
    You can clear your temp file a number of ways!! First way 1. Go to Start 2. Go to RUN
    http://img.photobucket.com/albums/v610/123...90/977a6e18.jpg 3. Type in temp, or TEMP, or Temp caps
    doesn't matter just as long as it says temp 4. Now if there is somthing there...then you should
    delete it..no harm will come to the computer.. if it gives you an error of this file is in use..then
    you cant delete it for now because the file is in use.... Second Way 1. Go To My Computer
    http://img.photobucket.com/albums/v610/123...90/3c3784d4.jpg 2. Go To Local Disk (C:) http://im....
  24. How To Read Large Files In Php.
    Tutorial on reading large files in PHP. (3)
    First of all don't use file() function instead use fread() functions. I think you should deploy
    the split-script technique. Its different from splitting your text file. Instead you get two scripts
    to do the same job. Or you can deploy the following method. First of all you should be knowing the
    size of the max text file which can be read in the max_execution_time on your Web Server. For that
    you need to use fread() function. with something like this: CODE $file=fopen("file.txt","r");
    $count=0; while(!feof($file)) { $data=fread($file,1024); print($count+" "); flu....
  25. Delete Files And Directories Using Php
    following up from creating and writing (11)
    How To Delete Files and Directories follow up from creating them Hello all and
    welcome to my second tutorial involving file management. In my previous tutorial , I explained how
    to create, write and read files. In this tutorial I'll explain how to remove the files and
    directories you took so long to create. I did not explain last time how to create directories as I
    did not know, now I do, you can use the mkdir() function. Now with this tutorial.... Removing
    Files Removing files can easily be done with the unlink() function: CODE unlink("....
  26. Adding Ur Own Files On Send To
    Windows xp (0)
    This tutorial will enable you to add places on the context menu under the Send To option. This is
    how u do it. Create a shortcut of the folder you want to add.Cut/Copy the shortcut and go to
    C:\Windows\Documents and Settings\Your user\Send To and paste the shorcut there. You can also
    rename the shortcut from shortcut to xxxxx to xxxxx Remember Your user stands for your userid that
    you have used to login. If you have any probs PM me.....
  27. How To Read And Write Files Using Php
    php :: reading and writing files (21)
    How To Read And Write And Files a simple trick using php For this script all you need is a
    php enabled server, a text document and a basic understanding of php itself: Beginning Create a
    text file called name.txt in any directory. Change the file permissions to 777 Create a empty
    php file in the same directory. You are now ready to begin reading and writing your files. If you
    just want to read the file scroll straight down to Reading the File else read through the whole
    tut /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> ....
  28. Css And Javascript Combined For Dynamic Layout
    use of different CSS files at same site (9)
    This tutorial is meant for people that are dealing with problems while coding their site at 100% of
    width. Important notice: Some people has JavaScript disabled, so they will not be able to load CSS
    file (take this in account when creating your website). How this script works. In the HEAD of your
    HTML document will apply this command, so variable.js file will be load at start: CODE
    In browser JavaScript file variable.js is loaded. This Javascript file consist of this parameters,
    copy this code and name it variable.js CODE // JavaScript Document if (sc....
  29. Jalbum 5.2
    Gallery Building Software (0)
    Just thought I would create a tutorial for those who want to use a gallery on their site but
    don't know how. This tutorial looks at JAlbum 4.4.2, which you can get by going here GET JAlbum
    5.2 // Step 1 JAlbum allows you to create a photo album without even leaving its main page. Here
    you can select the image directory, output directory, common album settings and control the album
    generation. // Step 2 To select an image directory, just drag and drop an image folder onto the
    Image Directory bar. JAlbum can read photos in JPG, GIF and PNG formats as well as movie ....

    1. Looking for building, unordered, list, anchors, list, files, folder
Similar
Deny Or Grant Users Access To Files Of Choice (vista) - Uses Bat Files To Deny Or Grant People Access To Files
Locking A Folder With No Software At All! - works on XP AND VISTA!!!
How To Create Pdf Files Using Free Tool - Introduction to use a free tool to create PDF file
Clearing Your Ie Tif - Clear your Temporary Internet Files on IE
How To Download Any Flv Files From Any Sites
Folder View In Kde 4.1
Debug Exe Files - How to debug an exe file.
Tutorial : Hide Folder Without Any Softwares - Descriptive enough!
Download Files Off Esnips.com - even now that the download button is gone!
Cakephp On Ubuntu - using your own public_html folder
How To Hide Your Important Files And Folders - In Ms. Windows, Without Using Programmes.
How To Better Compress Files In Winrar
Cpanel Analysis And Log Files - Part 4 of My 7 Part Tutorial
Dynamic Signatures - The Real Way To Go - Forget placing index.php in a signature.png folder.
How To Fix Problems With Shareaza - ONLY for people to download LEGAL files with.
How To Chmod Files
How To Create Self-unzipping Files - for beginners
How To Open Bam & Tt Files, long 3 part tutorial
Building An Address Book With Java
Php Script To Make A Link List - From the list of the Directory Files
Templating System Using Php Includes - Building a Dynamic site using Includes and flat-files.
How To Create Html Page Anchors - Click A Link And Take You To A Certin Place On The Same Page
How To Clear Your Temp Files
How To Read Large Files In Php. - Tutorial on reading large files in PHP.
Delete Files And Directories Using Php - following up from creating and writing
Adding Ur Own Files On Send To - Windows xp
How To Read And Write Files Using Php - php :: reading and writing files
Css And Javascript Combined For Dynamic Layout - use of different CSS files at same site
Jalbum 5.2 - Gallery Building Software

Searching Video's for building, unordered, list, anchors, list, files, folder
See Also,
advertisement


Building An Unordered List Of Anchors - From a list of files in a folder

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com