Parsing a text file - Post ID 75656

User 510015 Photo


Ambassador
92 posts

Hi Everyone,
I dont know if this is applicable to this section of the forum, but I have a need to be able to read a text file and display a section of it on a web page created in VSD.

Specifically, I need to display a piece of text contained in a short, 1 line comma delimited text file on the web page itself. The text file looks something like this internally...

"text item 1","text item 2","text item 3","text item 4"

I need to be able to open the text file somehow, and display one of the text items in the file on the page. Remember, I am using VSD to design my page. I'm sure some kind of code will have to be written, but even then, I'm not sure how to display the result.

Does anyone have an idea about how this might be done?
All my best,
Scott Tucker
User 597929 Photo


Registered User
1,332 posts

That really sounds like something out of the domain of HTML altogether, and into the realm of Perl scripting and php.
"You can't be a real country unless you have a beer and an airline - it helps if you have some kind of a football team, or some nuclear weapons, but at the very least you need a beer." -- Frank Zappa

Visit Spinland Studios: http://www.spinland.biz
User 510015 Photo


Ambassador
92 posts

Yes, I know some kind of coding will have to be done. I'm just wondering if there is a way to launch that code from VSD, and then somehow retrieve the results so it can be displayed on the form.

I can write a little applet that will open and read the file info. I just dont know how to launch it (from the page) and read the results back onto the page.
All my best,
Scott Tucker
User 2733 Photo


Ambassador
426 posts

This should work for ya Scott.

<?php

$dataFile = file_get_contents("data.txt");
$dataFile = rtrim($dataFile, ",");
//$dataFile = str_replace("\"", "", $dataFile); // uncomment to remove quotes from output

// Place each line of $dataFile into array
$spew = explode(",",$dataFile);
$count = count($spew);
$c = 0;

foreach ($spew as $spewed) {

echo htmlentities($spewed);

if ( $c < $count -1 )
echo "<br />";
$c++;
}

?>


http://digicave.org/speermints/parse/parser.php
Let's not get all hurt.
User 510015 Photo


Ambassador
92 posts

Hi David,
And thank you so much for taking the time to reply.

OK, I'm not a php coder, but am adept at some others, so I can kinda see that this is doing, I think.

What makes this code run? Do I simply stick it in an html pane on the vsd screen (I cant imagine that would work).

Also, your test file looks to have 10 line items. My file has only 1 line, with 5 text fields, separated by commas.
All my best,
Scott Tucker
User 2733 Photo


Ambassador
426 posts

Hmm. Lemme install VSD and see how this will work. I haven't a clue.

This is my data.txt file contents:

"text item 1","text item 2","text item 3","text item 4","text item 5","text item 6","text item 7","text item 8","text item 9","text item 10",


What does your look like?
Let's not get all hurt.
User 510015 Photo


Ambassador
92 posts

My data looks very much like that. There are only 5 fields, and I only need the info from 1 of them.

Here's what im doing, just in case the context helps any. I write software for a couple of different clients, and I put the updates and patches on our site so the users can download them.

I have a small text file (the csv data file) on the site that has the patch information in it. It contains, the patch file name to download, the latest version number, etc.

What happens now is my existing website reads the text file and displays the current version number on the screen. Here is a screen from my current site http://www.csaltc.com/page.cfm?PageID=138&CategoryID=70 as an example. See where it says "Current Version: 1.18.0". That number 1.18.0 is what is being read from that CSV file and is displayed on the screen.

Since my current site was written in a proprietary format that is difficult for me to maintain, I'm trying to reproduce it with something that I can maintain easily myself, and this is what you are helping me do at the moment.

The ugly answer is that I can physically write the version number on the page, and upload a whole new page each time that version number changes... but how ineligant is that???

Thanks again for all your help.
All my best,
Scott Tucker
User 2733 Photo


Ambassador
426 posts

Scott,

When you say updates and patches, what type of files are we talking about? Are they exe, msi, jar, etc?

I ask because if they're stored on the server, why not just read the file's attribs to get the version number?
Let's not get all hurt.
User 510015 Photo


Ambassador
92 posts

Hi David,
They are executables, and stored on the server, but I use a third party installation tool to package them up. I dont think reading the installation exe would provide the same version number of the actual patchfile exe stored inside it. The packaging tool is basically a wrapper, a self extracting exe.

Also, I still wouldnt have a clue about how to do that using VSD. I'm a desktop programmer.. i dont know the cool web stuff... yet.

Maybe I can just use the Flash Firestarter and create a simple display of the version number, and all I would have to do is upload the new flash script. Kind of overkill I think tho.
All my best,
Scott Tucker
User 2733 Photo


Ambassador
426 posts

Scott,

Here's a little something I whipped up.

http://digicave.org/speermints/parse/index.php

Copy this code and save it as data.php
<?php
// This file contains all patch and full version info.
// Edit only the attributes in "quotes"
// Do not use leading or trailing slashes for patch
// or full keys.
//
// This file is called by parser.php

$versionPatches = array ( // Let's begin our multidimensional array here

array ( // Item 0 in our array
'company' => "MedAmerica",
'subtext' => "Simplicity <sup>ii</sup>",
'version' => "1.18.0",
'patch' => "MASii/SiiPatch1-18-0.exe",
'full' => "MASii/SiiSetup.exe",
'logo' => "logo.dl.ma.jpg"
),

array ( // Item 1 in our array
'company' => "Penn Treaty",
'subtext' => "",
'version' => "2.65.0",
'patch' => "PTNA/PTNAUpdate2-65-0.exe",
'full' => "PTNA/PTNASetup.exe",
'logo' => "logo.dl.pt.jpg"
),

array ( // Item 2 in our array
'company' => "Prudential",
'subtext' => "LTC3",
'version' => "1.28.4",
'patch' => "PruLTC3/LTC3Patch1-28-4.exe",
'full' => "PruLTC3/LTC3Setup.exe",
'logo' => "logo.dl.pru.jpg"
)

); // Let's close our multidimensional array here
// Soy isn't that bad.
?>


Copy this code and save it as parser.php

<?php
include("data.php");
function showVersion( $numero = 0 ) {
global $versionPatches;
// ---------------------------------------------- BEGIN THE OUTPUT BELOW. CHEESE DANISH
echo "<center><table border=\"0\" cellspacing=\"0\" cellpadding=\"3\"><tr><td>&nbsp;</td><td width=\"10\" rowspan=\"3\">&nbsp;</td><td>Current version: ".$versionPatches[$numero]['version']."</td><td>&nbsp;</td></tr><tr><td align=\"right\" rowspan=\"2\" valign=\"top\"><font size=\"5\"><b>".$versionPatches[$numero]['company'].":</b></font><br>".$versionPatches[$numero]['subtext']."</td><td><input type=\"button\" name=\"cmdSubmit\" onclick=\"location.href='/csaPatches/".$versionPatches[$numero]['patch']."'\" value=\"".$versionPatches[$numero]['company']." Patch File\" style=\"width:210;\"></td><td rowspan=\"2\" valign=\"middle\" ><img src=\"http://www.csaltc.com/image/".$versionPatches[$numero]['logo']."\"></td></tr><tr> <td><input type=\"button\" name=\"cmdSubmit\" onclick=\"location.href='/csaPatches/".$versionPatches[$numero]['full']."'\" value=\"".$versionPatches[$numero]['company']." Full Install\" style=\"width:210;\"></td></tr></table></center>";
// ---------------------------------------------- END THE OUTPUT. HAVE COFFEE
unset($numero); // If you choose to call this file again on the same page,
// simply include it again and change the $numero variable
// Kirk out!
}
?>


Now, on your download pages where the existing table is you can use this instead.

<?php
include("parser.php");
showVersion(0); // MedAmerica
//showVersion(1); // Penn Treaty
//showVersion(2); // Prudential
?>


You download page must be able to parse PHP in the page. So, it's extension must either be .php OR you can config your .htaccess file to parse PHP in html pages. Ugh. I just noticed your download pages are .cfm. Umf.
Let's not get all hurt.

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.