Hi
If found a handy bit of code in your code library to search through the pages of a site.
When i tried it out I got the message
"Call-time pass-by-reference has been deprecated" whcih seems to have been generated by the presence of a "&" character in function call :
scroll ($new_dir, $terms, &$total);
from what i can understand it's used to increment the value of $total - but I started php with version 4 so I've never used this method
how would I go about replacing the "&" ?
here's the chunk of code
$tcount = 0; // initialize our file count
function scroll($current, $terms, $total)
{
$handle=opendir($current); // open the directory passed as the first argument
while (($file = readdir($handle))!=false) // keep cycling through all the files
{$first = ""; // initialize first occurance of the match
$fcount = 0; // initialize number of matches per file
$found = false; // initialize flag - true or false
$file_p = $current . "/" . $file; // create the path to the file for the a href
if (($file != ".") && ($file != "..")) // ignore . and .. files
{
if (is_file($file_p) && ((substr(strrev($file),0,1) == "3") || (substr(strrev($file),0,1) == "l") || (substr(strrev($file),0,1) == "m") ||(substr(strrev($file),0,1) == "p") ||(substr(strrev($file),0,1) == "t"))) // limit our search to
// php3, php, html, htm and txt files
{
$file_b = fopen($file_p, "r"); // open the file for reading
while (!feof($file_b)) // continue to end of line
{$line = fgetss($file_b, 2000); // try and remove all data between <> when reading
$line = trim($line); // trim any leading or trailing white space
if (!empty($line))
{
if (eregi($terms, $line, $regs)) // check that line for a match, using the keywords, the line, and returning an array of the matches
{$found = true; // set flag
$fcount++; //increment total found for this file
if ($first == "")
{$first = $line; // set the variable to display the first line where the match occurred
}
}
}
}
if ($found == true)
{$len = strlen($file_p); // this allows us to print the link, ignoring the starting /
$total++; // increment total number of file matches
print ("<p><a href ='" . $file_p . "'>" . substr($file_p, 2, $len-2) . "</a> contains ". $fcount . " match(es).");
print ("<br>First line matched: <i>" . $first . "</i>"); // display the first line in which the match was found
}
}
if (is_dir($file_p)) // if the file is a directory
{
$new_dir = $current . "/" . $file;
scroll ($new_dir, $terms, &$total); // call the function recursively when it is a directory
}
// end of if (($file != ".") && ($file != ".."))
}
// end of while (($file = readdir($handle))!=false)
}
closedir($handle); // close the directory
// end of function
}
scroll(".", $key, &$tcount); // initial call to the function, passing it the current directory as the start, the cleaned up search terms and the total number of files found - this is passed by reference so it can be incremeneted script-level
if ($tcount > 0)
{print ("<p>We found " . $tcount . " total match(es). Care to <a href = \"search.html\">search again?</a>");}
else
{print ("<p>We found failed to find a match, please <a href = \"search.html\">search again.</a>");}
} // end of keywords not empty
?>
any ideas ?
or is there another recursive search snippet on phpBuilder?
thanks