There are a couple of ways to do this, depending on what you're looking to
accomplish. One involves treating the contents of the text file as literal
text, not as HTML. This comes directly from the manual, under the
get_html_translation_table() function. Here's a quick copy & paste:

$trans = get_html_translation_table(HTML_ENTITIES);
$str = "Hallo & <Frau> & Krämer";
$encoded = strtr($str, $trans);

The $encoded variable will now contain: "Hallo &amp; &lt;Frau&gt; &amp;
Kr&auml;mer".

Another possibility is this: If you have your text files set up in a
specified format, you can make your code parse the tables and put them out
in a specific format. I use that option, simply because I find it easier to
use. A file structured like this:

------------------text file start------------------
-identity
Litany Against Fear|http://www.bbc.co.uk/dna/h2g2/A594489|Bene Gesserit
Litany Against Fear (From Frank Herbert's "Dune")|-
You In Lego|http://www.reasonablyclever.com/|Picture yourself made in
Lego!|-
You In South Park|http://southpark.gamesweb.com/flash/sp-studio.html|Picture
yourself in South Park|-
You As A Virtual Model|http://www.myvirtualmodel.com/|You as a virtual
model|-
*
-software
Mailwasher Email Filter|http://www.mailwasher.net/|Preview, delete, bounce
emails from your server before downloading them to your computer|-
EO Video|http://www.eo-video.com|All-in-one video player, converter|hot
*

..
..
..
..
and so on (no blank lines at the end of the file; one line per link
description)
------------------text file end------------------
is parsed by this routine of code:
------------------code start------------------
// initialize variables; not necessary but generally good coding practice
$linkcat = "";
$catcount = 0;
$ltf = 0;
$linkref = file("links.txt"); // load text file
$linkcount = count($linkref); // count links/lines
echo "  <table border=1 cellpadding=1 cellspacing=1>\n"; // start the table
for ($lrcount = 0; $lrcount < $linkcount; $lrcount++) { // go through all li
nks
  $lcomptobj = $linkref[$lrcount]; // set a comparison object
  if (substr_count($lcomptobj, "*") < 1) { // if the line isn't a "*" for a
category divider
    if (substr($linkref[$lrcount],0,1) == '-') { // if it's prefaced by a -,
for a category name
      $linkcat = trim(substr($linkref[$lrcount],1));
   $outstr = "  <tr><th colspan=2>".$linkcat."</th></tr>\n"; // display a
table header with category name
    } else {
   list($_hname, $_url, $_title, $_linkstat) = explode("|",
$linkref[$lrcount]); // separate the line at the | characters
      $outstr = "  <tr><td><a title=\"".$_hname."\" href=\"".$_url."\"
target=\"_blank\">".$_hname."</a></td>";
   $outstr .= "<td>".$_title.(($_linkstat == "hot") ? " (hot link)" :
"")."</td></tr>\n"; // format the table line with descriptions and URL
titles
    }
 if (($linktype == $linkcat)||($linktype == "all")) { echo $outstr; }//
display the line if the category matches or if all categories selected
  }
}
echo "  </table>\n\n";
------------------code end------------------

I made this code for my site because I wanted to display by categories and
let me choose only one category if I wanted to, by calling a URL like
"links.php?linktype=identity". It's not the best method, and not the most
efficient, but it's just the one I wanted to use. Sorry if the text in this
message seemed tough to read :P


> Message-ID: <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> From: "Bryan Luisana" <[EMAIL PROTECTED]>
> Date: Thu, 24 Oct 2002 19:38:44 -0400
> Subject: text file parsing
>
> Hello,
>
> I have only been working with php for about 2 hours now so bare with me if
I
> type something stupid.
>
> I am trying to open up a remote text file, parse the file, and output the
> parsed text as html.  As of now I can open the file read characters into a
> buffer and then output them as html.  My problem is with parsing the
buffer
> to get to the text I want to output.
>
> Should I read the entire file into an array?  Then output the parts of the
> array I want to show?  If so please post some type of example code.
>
> Does php have functions to move through a file and choose which characters
> you want to put into an array or a buffer?
>
> Any help would be greatly appreciated.
>
> Thanks for your time


-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to