Entry
Looking for ideas on how to include file "color.txt" but only if it contains the word "green".
Oct 1st, 2009 04:06
jsieoa gide, Scott Mandarich, Sarah Turner, healthy man, dman, Averick Just, http://65.182.191.43/d/chanel.html
Ok... Got it to query and include (echo) a single file (if contents
contained the keyword)
$file="/full/path/to_file/text2.txt";
$fd = fopen ($file, "r");
$contents = file($file);
$number = count($contents);
for($i=0;$i<$number;$i++) { if(strstr($contents[$i],'green')) echo
$contents[$i]; }
Also got it to query several files and include (echo) only those that
contained the keyword.
$file_names = array
('text1.txt', 'text2.txt', 'text3.txt', 'text4.txt');
foreach($file_names as $file) {
$contents = implode("",file("$file"));
if(strstr($contents,'green')) { echo nl2br($contents); }
}
Naturally the above would be enclosed in PHP start/end tags. And an
else statement can be tagged on (pardon the pun). Something like this
should do it:
$file_names = array
('text1.txt', 'text2.txt', 'text3.txt', 'text4.txt');
foreach($file_names as $file) {
$contents = implode("",file("$file"));
if(strstr($contents,'green')) { echo nl2br($contents); }
else {
include($other);
} }
Thanks go to the nice folks over at devshed.
Later,
averick
------------------------------------------------------------------------
http://bozicnipokloni.blogspot.com/
http://karacsonyiajandekok1.blogspot.com/
http://kerstcadeaus.blogspot.com/
http://presentesdenatal1.blogspot.com/
http://kysymyksenvastaukset.blogspot.com/
http://festivalfestiviteiten.blogspot.com/
http://svaretblog.blogspot.com/
http://festivalbl.blogspot.com/
http://regalidinatale1.blogspot.com/
http://weihnachtsgeschenke1.blogspot.com/
http://cadeauxdenoel1.blogspot.com/
http://christmasgifts215.blogspot.com/
http://festivaloslavy.blogspot.com/
http://fragebeantwortet.blogspot.com/
http://festivblogi.blogspot.com/
http://cadouridecraciun1.blogspot.com/
http://julegaver1.blogspot.com/
http://christmasgifts211.blogspot.com/
------------------------------------------------------------------------