Help debug this file?
Posted: Sun Sep 03, 2006 11:00 pm
feyd | Please use
The
part isnt working.
Any advice would be appreciated.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I hope this is clear enough.Code: Select all
<?php
function deleteLine($searchQuery, $filename) {
$file = file($filename);
$write = '';
for($i=0; $i < count($file); $i++)
if(strpos($file[$i], $searchQuery) === false)
$write .= $file[$i];
$handle = fopen('link.txt', 'w');
fwrite($handle, $write);
fclose($handle);
}
if (in_array(test, file('link.txt'))) {
echo 'works.';
} else {
if(strpos(file_get_contents('http://www.test.com/'), 'test') !== false) {
$filename = 'link.txt';
$somecontent = "\n Test.com <BR> Description: A test website<HR><HR> \n";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!($handle = fopen($filename, 'a')))
die("Cannot open file $filename.");
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === false)
die("Failed to write to $filename.");
echo "SUCCESS. \"$somecontent\" was written to file $filename.";
fclose($handle);
}
} else deleteLine('test','link.txt');
}
?>Code: Select all
if (in_array(test, file('link.txt'))) {
echo 'works.';Any advice would be appreciated.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]