Development Tutorials
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsCommunityDevelopment Tutorials

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 18th, 2002, 08:11 PM
mytch mytch is offline
Dev Articles Novice (500 - 999 posts)
 
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 589 mytch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Article Discussion: Working With Text Files in PHP

Working With Text Files in PHP If you have any questions or comments about this article then please post them here.

You can read the article here .

Reply With Quote
  #2  
Old December 20th, 2002, 08:57 PM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
ho3w can i make an email template. Example: when someone submits a comment, i want the mail form to pull in a HTHL document that gets used as the email template which will be sent to the user.
__________________
regards,


Fulton

Reply With Quote
  #3  
Old December 21st, 2002, 09:39 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Do you want to store the template in an external file, or do you want to store the html code within your script?
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #4  
Old December 22nd, 2002, 03:20 AM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
Hi,
I would like to store the template in HTML format as an external file.

Reply With Quote
  #5  
Old December 22nd, 2002, 03:27 AM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
i have got it so the html file gets pulled into my email script, but when you recieve the email, you receive HTML and not frmatted HTML

Reply With Quote
  #6  
Old December 24th, 2002, 06:32 AM
bramp bramp is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 3 bramp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I would like to point out some mistakes on this article. A friend of mine tried using the examples and ended up with something that didn't work

Basically this code is just wrong:
PHP Code:
<?php 

$fp 
= @fopen("person.data""rb") or die("Couldn't open file"); 
$data fread($fpfilesize($fp)); 

while(!
feof($fp)) 

$data .= fgets($fp1024); 


fclose($fp); 

...

?>


Firstly filesize($fp), In the php documentation URL states that filesize accepts one parameter which is a string, not a file pointer. This was causing problems for my friend. The correct line should be:
$data = fread($fp, filesize("person.data"));

Secondly why are we even doing the above line if we have that while loop? Both aren't needed!... The finished code should look like this:
PHP Code:
 $fp fopen("person.data""rb") or die("Couldn't open file"); 

$data '';
while(!
feof($fp)) 

$data .= fgets($fp1024); 


fclose($fp); 

... 

or
PHP Code:
 $fp fopen("person.data""rb") or die("Couldn't open file"); 
$data fread($fpfilesize("person.data")); 

fclose($fp); 

... 


Both do the same thing.

Now there is more than 1 way to do anything in a programming language, and I would like to comment a "better" way of doing the explode("\r\n", $data); would of to use the file URL function which opens a file and returns a array of lines. The entire code would be:

PHP Code:
 $values file("person.data");

echo 
"Name: " $values[0] . " " $values[1] . "<br>"
echo 
"Age: " $values[2] . "<br>"
echo 
"Sex: " $values[3]; 


Maybe also some error checking should go in there...

But anyway thats my comments on the article, I never actually read past the first page, and I hope the author will be able to make corrections/improvements to his code.

bramp

Reply With Quote
  #7  
Old January 11th, 2003, 09:23 PM
Zeshin Zeshin is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 1 Zeshin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
For some reason, I can read files fine, but when I try and open a file for writing, it gives this "Warning: fopen("newfile.txt", "w") - Permission denied" error. And I have tried putting a file named "newfile.txt" in that directory and it still didn't work, but even if it wasn't there it should create it..I don't understand why it's not working..

Reply With Quote
  #8  
Old February 13th, 2003, 12:51 PM
ru_ie ru_ie is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 2 ru_ie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
nothing been written.

Hi,

Good article - I've got the code working fine - but nothing is inputted into the .data/.txt file - it will implement any text it Email: NAme: but the passed variable from the form won't input? any answers.?

R

Reply With Quote
  #9  
Old February 22nd, 2003, 12:25 AM
kiruba kiruba is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 5 kiruba User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i am developing a web mail client with PHP.i have used text files to create address book.

i have some serious problems:
can i update the information in the text file
how can i delete a row

please give me the function or method used to delete/update textfiles.it is very urgent

cheers
kiruba

Reply With Quote
  #10  
Old March 18th, 2003, 12:43 AM
Ty* Ty* is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 2 Ty* User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to Ty* Send a message via MSN to Ty* Send a message via Yahoo to Ty*
Line #

How would I retrieve the line number on which certian data is located?

The reason I ask is I am developing a "database" application to store/retrieve college scholarship information where, unfortunately, MySQL is not an option for storing the data. My original approach to this delima was to use xml to store the entries, as this would allow for ease of presentation later on, but I have not found an easy way of deleting individual data entries from the xml file when needed. Thus, I have enlisted the use of flat files as the method of storing the scholarship information. However, being the newcomer that I am, I am unaware of any method of retrieving the line number of given data. If anyone can help me with this, or my xml problem, I would greatly appreciate an immediate response by email or reply to this post. Thanks!

Last edited by Ty* : March 18th, 2003 at 12:47 AM.

Reply With Quote
  #11  
Old October 23rd, 2003, 07:27 AM
sanjeev sanjeev is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: jaipur - rajasthan - india
Posts: 1 sanjeev User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Forbidden

hi guys !

here is my problem when i try to creat file with fopen() this error will come :

<Error Starts>

Forbidden
You don't have permission to access /test/create_file.php on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


--------------------------------------------------------------------------------

Apache/1.3.28 Server at directory.myrajasthan.com Port 80

<Error End>

and here is my code :

<Code Starts>

<?php

$fp = fopen("newfile.txt", "w") or die("Couldn't create new file");

$numBytes = fwrite($fp, "\r\nLook, it's a very first line!");

fclose($fp);

echo "Wrote $numBytes bytes to the end of newfile.file!";

?>

<Code End>

can u please tell me why this happend ?

Many Thanks !!!

sun

Reply With Quote
  #12  
Old November 18th, 2003, 04:47 PM
ettis ettis is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 1 ettis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Nice script.. but.. If I would like to add colors to the script.. like
Sex: <input type="radio" name="sex" value="M">

If I want that to be color green, how do I make that?

/ 1:an

Reply With Quote
  #13  
Old December 5th, 2003, 12:00 AM
KiltedMile KiltedMile is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 2 KiltedMile User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Read particular line from txt file

This problem is killing me, and my knowledge of PHP….

I have a text file labeled “shows.radio” the contents are as follows:

2-4pm Show name 1
4-6pm Show name 2
6-8pm Show name 3
8-10pm Show name 4
10-12pm Show name 5


I would like to display one line from that text file when referenced by the time, so basically if the variable $time = 4-6pm is parsed to a script, the script will open the txt file and will display only the show tile “Show name 2” in the browser. How can this be done?

Reply With Quote
  #14  
Old May 2nd, 2004, 12:21 PM
globalweb globalweb is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 1 globalweb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi..sorry to butt in..but I have a similar problem.

Here is my code. This works in that I get an email containing the contents of the text file 'sub_email1.txt' , but for some reason I can not APPEND to the EMAIL message variable. This is for a newsletter subscription and I need to append a REMOVE ME link. Remember, I get the email with the file contents but not with the appended information.

Please help as I am going crazy.

(the red code doesn't seem to work)
__________________________________________________ _____________________________________
$filename = 'sub_email1.txt';
$fp = fopen($filename, "a+") or die("Cant Open file");
$chunk = fread($fp, filesize($filename));
fclose($fp);
$message = $chunk;
$message .= '<a href="friend_in.php?rid='.$_POST['rid'].'" target="_blank">Click Here To Signup.</a><br>';
$message .= '<br><a href="
remove_me.php?rid='.$_POST['rid'].'&sm_id='.$in_id.'" target="_blank">Click Here To Unsuscribe</a><br>';

$emaili = "staff@mycompanyemail.com";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $from <$emaili>\n";

mail($_POST[email], 'Newsletter Subscription Information', $message, $headers);

__________________________________________________ _________________________________

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsCommunityDevelopment Tutorials > Article Discussion: Working With Text Files in PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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 On
HTML code is Off