Click to See Complete Forum and Search --> : [RESOLVED] writing to a file


Heavy Metal
04-01-2006, 06:50 PM
I was wonding what the code line would be to see if something is in a file?(would appriciate if you would include comments as i like to know what the code does so i can learn)

bathurst_guy
04-01-2006, 06:55 PM
Have you searched first???
Try reading through some of these posts (http://www.webdeveloper.com/forum/search.php?searchid=1072959), I'm sure you will find your answer.

balloonbuffoon
04-01-2006, 06:59 PM
//get the entire contents of a file
$contents = file_get_contents($filename);

//determine whether the string ($find) is anywhere in the file
//strpos() finds the position of a string ($find) inside of another string ($contents)
//if it is not found, it will return false
if (strpos($contents, $find)===false) {
//do something if string isn't in file
} else {
//do something if string *is* in file
}


--Steve

balloonbuffoon
04-01-2006, 07:02 PM
And if you need case-insensitive searching, replace strpos() with stripos().

--Steve

Heavy Metal
04-01-2006, 07:36 PM
And once again you all come through for me. You guys rule.:)

Heavy Metal
04-01-2006, 08:09 PM
how do you run a function when a form submits?

Heavy Metal
04-01-2006, 08:30 PM
no answers?

NogDog
04-01-2006, 08:40 PM
no answers?
Dude, it's Saturday night, Final 4 on TV, and you want a response after only 20 minutes - on a thread that's marked as resolved?

How about starting a new thread since it's a new question (and this one is resolved). I'll lock this thread so potential responses don't get spread between threads.