[advanced search]
Results from the most recent live auction are here.
16 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming > CODE
User Name
Password

Old 12-29-2003, 12:47 AM   · #1
deadserious
Senior Member
 
Trader Rating: (13)
Join Date: Aug 2002
Posts: 1,300
NP$: 2.85 (Donate)
deadserious has a spectacular aura aboutdeadserious has a spectacular aura about
Arrow Opening a text file and displaying the results in browser with PHP, Perl, and Python

Here's a few code snippets of the various methods different languages use for manipulating text files. Each example opens file.txt for appending, writes a string to it, reopens the file for reading and outputs the entire content of the text file to the browser. If you want to overwrite the content of the file rather than append to it you can switch the "a" to "w" for both PHP and Python and change the ">>" to ">" for Perl. There's other methods of doing this for each language, but this should give a good idea of how certain functions for each language compare to each other.

PHP
Code:
<? $file = fopen ("file.txt", "a"); fwrite ($file, "This is a PHP test<br />n"); fclose ($file); $file = fopen ("file.txt", "r"); $lines = fread ($file, filesize ("file.txt")); fclose ($file); echo $lines; ?>


Python
Code:
#!/usr/bin/python print "Content-type: text/html\n\n" file = open('file.txt','a') file.write("This is a Python test<br />n") file.close() file = open('file.txt','r') for lines in file.readlines(): print lines, file.close()


Perl
Code:
#!/usr/bin/perl print "Content-type: text/html\n\n"; open (FILE, ">>file.txt"); print FILE "This is a Perl test<br />n"; close (FILE); open (FILE, "file.txt"); @lines = <FILE>; close (FILE); print @lines;


Please register or log-in into NamePros to hide ads
deadserious is offline   Reply With Quote
Old 05-15-2004, 07:58 PM   · #2
axilant
Account Closed
 
axilant's Avatar
 
Name: Cody Selzer
Location: /etc/passwd
Trader Rating: (40)
Join Date: May 2004
Posts: 2,194
NP$: 0.00 (Donate)
axilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to behold
Member of the Month
July 2005
Thanks... i'm learning perl
axilant is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


Site Sponsors
Traffic Down Under Exdon Click to Watch Instant Video
Advertise your business at NamePros
All times are GMT -7. The time now is 10:52 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0