Reply LinkBack Thread Tools Search this Thread
Old 16-12-2007, 10:12   #21 (permalink)
Hunch
Grumpy old man
 
Hunch's Avatar
 
Join Date: Oct 2007
Location: North Japan
Posts: 1,696
Another thought that just occurred. If you want to use a text file, why not use the method that most php config files use.

So instead of your textfile containing this:

Code:
yes

instead, make it like this:

Code:
<?php $available = "yes"; ?>

Then all you need to do is add a line to your page saying

include "word.txt";

and the variable will automatically be set without having to check anything. Plus you've got the basis of a config file which you could easily use to store more settings if you require them in the future.
  Reply With Quote
Old 16-12-2007, 10:44   #22 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 4,972
very good. *****
__________________
  Reply With Quote
Old 16-12-2007, 14:07   #23 (permalink)
mgpwr
with a hint of lemon
 
mgpwr's Avatar
 
Join Date: Aug 2006
Location: Sheffield
Posts: 496
On my cms, i have a form with two options:

Code:
<option value="Not Just Yet">Not Available</option> <option value="yes">Available</option>

which then the option value is posted to this file

Code:
<?php $storefile = "avail.txt"; function writealltofile($text,$file){ $fp = fopen ($file, "w") or die("Couldn't open $file"); flock ($fp,LOCK_EX); fwrite($fp, "$text"); flock ($fp,LOCK_UN); fclose ($fp); } function gethtmlfromfile($file){ $filename = "$file"; $htmlfromfile = ""; $fp = fopen ($filename, "r") or die("Couldn't open $filename"); while (! feof($fp)){ $line = fgets($fp,1024); $htmlfromfile = "$htmlfromfile"."$line"; } $htmlfromfile = stripslashes("$htmlfromfile"); return $htmlfromfile; } if($var) { writealltofile($var,$storefile); } $varfromfile = gethtmlfromfile('avail.txt'); echo "<meta http-equiv='refresh' content='2;url=index.php' />"; echo "Availability Changed, Please wait a moment..."; ?>

However, if i change the value of the options to make it so that the script adds:

Code:
<?php $available = "yes"; ?>

instead of just
Code:
yes

its ouputs with these \\ that then causes it not to work
__________________
Online portfolio: mgpwr.co.uk
  Reply With Quote
Old 16-12-2007, 16:29   #24 (permalink)
ahref
Registered User
 
ahref's Avatar
 
Join Date: Dec 2007
Posts: 20
lol second thread ive posted this on

try using stripslashes() again on the output line
  Reply With Quote
Old 16-12-2007, 17:05   #25 (permalink)
wheedwacker
competitionmaster 2.0
 
wheedwacker's Avatar
 
Join Date: Oct 2006
Location: USA
Posts: 1,420
Try

$word = file_get_contents('fullServerPath/word.txt');
if($word=='yes') {
echo 'available';
} else {
echo 'not available.';
//show not for hire stuff
}

Replace fullServerPath with the whole path to the word.txt file.
(I actually tested this one, and it does work)
  Reply With Quote
Old 16-12-2007, 17:40   #26 (permalink)
Hunch
Grumpy old man
 
Hunch's Avatar
 
Join Date: Oct 2007
Location: North Japan
Posts: 1,696
So looking at your code, you're writing to this file yourself (i.e. you're creating the PHP for the writing of the "yes/no" to the file and the reading of the same)?
  Reply With Quote
Old 16-12-2007, 18:42   #27 (permalink)
Shiro
shiro
 
Shiro's Avatar
 
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 2,639
Since you have access to the cms code, switch it up to the way Hunch told you earlier. It will be more efficient, and will be less hassles to debug, with less chance of errors, and nicer sleeker code.
  Reply With Quote
Old 16-12-2007, 18:59   #28 (permalink)
Hunch
Grumpy old man
 
Hunch's Avatar
 
Join Date: Oct 2007
Location: North Japan
Posts: 1,696
Yeah, you got there before me. That was what I was coming around to. I was a bit baffled because previously he'd said he was using the CMS to create the file, as a reason not to follow the way I'd suggested (which I still thing is a lot neater and easier than reading and writing strings to files).
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8