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

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 February 3rd, 2005, 12:33 AM
Shaunyboy Shaunyboy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 21 Shaunyboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 45 m 10 sec
Reputation Power: 0
Load text files as variables

Can anyone help me to load a text file, and turn it into a variable? Any help appreciated, thanks in advance.

Reply With Quote
  #2  
Old February 3rd, 2005, 10:26 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8

Reply With Quote
  #3  
Old February 9th, 2005, 11:50 PM
Shaunyboy Shaunyboy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 21 Shaunyboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 45 m 10 sec
Reputation Power: 0
Thanks. But using that code I ended up getting a few errors. I think it partially worked, but there must be something wrong that I've done. Would appreciate it if someone could have a look at the errors that come up on http://dump.hollosite.com/blog/postsave.php
and could check the code pasted here:

<?php
echo header( 'location:index.php' );
$fp = fopen("admin/gmttime.txt", "r");
$gmttime = fread($fp, filesize($fp));
$fp = fopen("admin/yourname.txt", "r");
$yourname = fread($fp, filesize($fp));
$fp = fopen("admin/timezone.txt", "r");
$timezone = fread($fp, filesize($fp));
$hourdiff = $gmttime + 10;
$timeadjust = ($hourdiff * 60 * 60);
$time = date("g:i a",time() + $timeadjust);
$title = date("GidMy",time() + $timeadjust);
$Date = '<div id="pagetitle">'.date("l, d F Y",time() + $timeadjust).'</div>';
$From = "Posted by ".$yourname." at ".$time." ".$timezone.".";
$Post = $_POST["post"];
$AddComment = '<a href="index.php?post='.$title.'">Add a comment!</a>';
$fn = fopen($title.".txt", "x") or die("Please don't post twice in the same minute.");
fwrite($fn, "\r\n" . '<br />');
fwrite($fn, "\r\n" . '<br />');
fwrite($fn, "\r\n" . $Date);
fwrite($fn, "\r\n" . '<br />');
fwrite($fn, "\r\n" . $Post);
fwrite($fn, "\r\n" . '<br />');
fwrite($fn, "\r\n" . $From);
fwrite($fn, "\r\n" . '<br />');
fwrite($fn, "\r\n" . $AddComment);
fclose($fn);
$fp = fopen("archive.txt", "a") or die("Error creating/writing to new file.");
fwrite($fp, "\r\n" . '<?php Include("'.$title.'.txt"); ?>');
fclose($fp);
$fp = fopen("admin/archive.txt", "a") or die("Error creating/writing to new file.");
fwrite($fp, "\r\n" . '<a href="index.php?post='.$title.'">Edit '.$title.' post</a>');
fclose($fp);

?>

Thanks again.

Reply With Quote
  #4  
Old February 14th, 2005, 11:10 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
What exactly are the errors you get?

Reply With Quote
  #5  
Old February 15th, 2005, 12:24 AM
Shaunyboy Shaunyboy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 21 Shaunyboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 45 m 10 sec
Reputation Power: 0
Sorry have fixed that particular problem now. I am now wondering how to use stripslashes correctly. When I try to use them, Nothing happens, its as if they're not even part of the code. Thanks for the help.

Reply With Quote
  #6  
Old February 15th, 2005, 08:44 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
Stripslashes simply takes the slash away when its used to escape a character.

From the documentation
PHP Code:
<?php
$str 
"Is your name O\'reilly?";

// Outputs: Is your name O'reilly?
echo stripslashes($str);
?>


How are you trying to use it?

Reply With Quote
  #7  
Old February 18th, 2005, 02:54 AM
Shaunyboy Shaunyboy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 21 Shaunyboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 45 m 10 sec
Reputation Power: 0
Probably in a way in which it won't work :P

$fn = fopen("../archive/".$title.".txt", "x") or die("Please don't post twice in the same minute.");
stripslashes( fwrite($fn, "\r\n" . '<br />'));
stripslashes( fwrite($fn, "\r\n" . '<br />'));
stripslashes( fwrite($fn, "\r\n" . $Date));
stripslashes( fwrite($fn, "\r\n" . '<br />'));
stripslashes( fwrite($fn, "\r\n" . $Post));
stripslashes( fwrite($fn, "\r\n" . '<br />'));
stripslashes( fwrite($fn, "\r\n" . $From));
stripslashes( fwrite($fn, "\r\n" . '<br />'));
stripslashes( fwrite($fn, "\r\n" . $AddComment));
fclose($fn);

Reply With Quote
  #8  
Old February 18th, 2005, 08:35 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
You're trying to write to the comment to a file?

You might want to try:
PHP Code:
 $Post stripslashes($Post);
$AddComment stripslashes($AddComment);

$message "<br />\r\n<br />\r\n$Date\r\n<br />\r\n$Post\r\n<br />\r\n$From\r\n<br />\r\n$AddComment";

$fn fopen("../archive/".$title.".txt""x") or die("Please don't post twice in the same minute.");

if (
fwrite($fn$somecontent) === FALSE) {
    echo 
"Cannot write to file";
    exit;
}

fclose($fn); 


I question your message "Please don't post twice in the same minute."
There might be other reasons the file doesn't open...

Reply With Quote
  #9  
Old February 18th, 2005, 04:58 PM
Shaunyboy Shaunyboy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 21 Shaunyboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 45 m 10 sec
Reputation Power: 0
That works great.

I hate to bother you again, though. I want to be able to read a file line by line, making each line part of an array, then use array_reverse to flip it around.

I'm getting an error saying:

Warning: main(Array): failed to open stream: No such file or directory in /home/www/dump.hollosite.com/blog/files/main.txt on line 25

Warning: main(): Failed opening 'Array' for inclusion (include_path='.:/usr/local/lib/php') in /home/www/dump.hollosite.com/blog/files/main.txt on line 25




When using this code:

$archive= array ( file("files/archive.txt"));
$main = array_reverse($archive);
Include ("$main");


I've obviously done something wrong, but can't work it out. Thanks for all the help.

Reply With Quote
  #10  
Old February 19th, 2005, 03:56 PM
Shaunyboy Shaunyboy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 21 Shaunyboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 45 m 10 sec
Reputation Power: 0
Have now solved the problem, thanks for all the help.

Reply With Quote
  #11  
Old February 19th, 2005, 05:10 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
How did you fix your problem?

Reply With Quote
  #12  
Old February 20th, 2005, 01:10 AM
Shaunyboy Shaunyboy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 21 Shaunyboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 45 m 10 sec
Reputation Power: 0
Figured out I was trying to Include an array, rather than Print ing it :P

Reply With Quote
  #13  
Old February 24th, 2005, 11:53 PM
Shaunyboy Shaunyboy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 21 Shaunyboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 45 m 10 sec
Reputation Power: 0
I'm having a bit of a problem with sessions. I've neaver used them before, and I'm probably missing something out which needs to be there. Could someone please mention the essential functions I need for a session? Thanks in advance.

Reply With Quote
  #14  
Old February 25th, 2005, 11:07 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
This would take the conversation out of scope of the original question, a new thread might have been a better idea

But anyways... make sure session_start() is [one of] the first functions called on your page.
then store stuff in the $_SESSION variable... eg: $_SESSION['username']='Bill';
session_destroy() kills the session too

the documentation is a good source of help. Not to mention many google'ing tutorials, and even devarticles articles.

Reply With Quote
  #15  
Old February 27th, 2005, 03:06 AM
Shaunyboy Shaunyboy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 21 Shaunyboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 45 m 10 sec
Reputation Power: 0
Yeh, i thought considering it was still part of the same project, that i would post here, instead of clogging up the forums with unnecessary threads :P

I have it working now, thankyou very much for your help.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Load text files as variables


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump