If, line 5 of file test.txt = "color"..do...else do ...
Good day to you, I woking on a script which is customizable for the web editor to change some option on the way some item on the page are displayed. My question is: How can I put in my code something that would do : if in file "setting.txt" row 5, the word "colored" appears do this piece of code else , do this piece. This would be within a function. Thanks !
That's why we are not alone on earth... let's build !
I'd be inclined to use an INI file, so that it's easily formatted for anybody to edit, and then create a base class to handle the core stuff, and then extend onto it for customisation colours, customisation sizes, etcetera.
I'd rather not have to load a whole file into memory (the OP didn't say how big it was) so here's something which only grabs what we're looking for. Of course, it's not perfect but might give you an new way of finding the right line in the file (compared to those above). It's basically putting xenon's post into code form.
function fline($file, $pos)
if ( ! $fp = fopen($file, 'r'))
throw new RuntimeException('Unable to read file '.$file);
$line = NULL;
$lnum = 0;
while ($lnum++ < $pos && ! feof($fp))
$line = fgets($fp, 10240);
// rtrim the line because fline includes a trailing newline
$line = rtrim(fline('settings.txt', 5));
if ($line == 'colored')
// Do something colourful
// Do something boring