Add new comment

A PHP Script for Viewing Text Files

Submitted by Bill St. Clair on Sun, 2008-02-03 21:12.

I've been writing PHP scripts recently to interact with the Loom.cc anonymous electronic vault and trading system. I've wanted to be able to show off my code, and my emacs design text files, without requiring the download of a source TAR file. So I wrote a little script that displays a text file, with a fixed width font and word wrap, and, optionally, searching for a phrase and/or displaying line numbers.

Go to billstclair.com/loom/viewtext.php?file=viewtext.php to direct the script to view itself.

You can add line numbers by adding "&numbers=yes" to that URL.

You can search for a phrase, e.g. "replace", by adding "&search=replace" to the URL. Each instance of the search string becomes a link that you can click on to move to the next one.

Finally, such file viewers are security risks if you're not careful. But I was. Only files explicitly named in "viewtext.txt" may be viewed. That list is displayed if you leave off the "file": billstclair.com/loom/viewtext.php. This makes it easy to drop a copy of viewtext.php in a directory on your web site, and enter the names of the files you want to show in viewtext.txt in that directory.

Go wild!

( categories: Loom )

Reply



The content of this field is kept private and will not be shown publicly.


*

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <i> <b> <u>
  • Lines and paragraphs break automatically.
  • Web and e-mail addresses are automatically converted into links.
  • You may quote other posts using [quote] tags.
  • Easily link to terms in various wikis. For help, see interwiki.
  • Easily link to terms in various wikis. For help, see interwiki.
  • You may quote other posts using [quote] tags.
  • You can use BBCode tags in the text, URLs will be automatically converted to links
Verify comment authorship
Captcha Image: you will need to recognize the text in it.
*
Please type in the letters/numbers that are shown in the image above.