Explode Text File of URLS into HTML links


/ Published in: PHP
Save to your folder(s)

This is a simple 'text to array for output' script that I've used a few times for my clients. Hope you like!


Copy this code and paste it in your HTML
  1. <?php
  2. //locate file for collection
  3. $userfile= file_get_contents("links.txt");
  4.  
  5.  
  6. /* this user file (links.txt) is simply a series of URLS, each on one line like so:
  7. www.xxxxxxx.org
  8. www.yyymmmzzz.com
  9. www.someotherurl.com
  10.  
  11. */
  12.  
  13. //explode each line of hte links.txt file directly into an array
  14. $links = explode("\n",$userfile);
  15.  
  16. //sort($links) or shuffle($links) or whatever this array
  17. sort($links);
  18.  
  19. //output the array for display.
  20. foreach ($links as $text) {
  21. echo '<a href="http://' . $text .'">' . $text . '</a><br />' . " \n";
  22. }
  23.  
  24. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.