Posted By

chicagowebmanagement on 10/08/10


Tagged

php file array text


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

beebs93


Explode Text File of URLS into HTML links


 / Published in: PHP
 

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

  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  

You need to login to post a comment.