本文整理汇总了PHP中readHeader函数的典型用法代码示例。如果您正苦于以下问题:PHP readHeader函数的具体用法?PHP readHeader怎么用?PHP readHeader使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readHeader函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: main
function main()
{
if (strcmp('4.1.0', phpversion()) > 0) {
die("Error: PHP version 4.1.0 or above required!");
}
if (!($file = fopen("search.idx", "rb"))) {
die("Error: Search index file could NOT be opened!");
}
if (readHeader($file) != "DOXS") {
die("Error: Header of index file is invalid!");
}
$query = "";
if (array_key_exists("query", $_GET)) {
$query = $_GET["query"];
}
echo "<input class=\"search\" type=\"text\" name=\"query\" value=\"{$query}\" size=\"20\" accesskey=\"s\"/>\n";
echo "</span>\n";
echo "</form>\n";
echo "</div>\n";
$results = array();
$requiredWords = array();
$forbiddenWords = array();
$foundWords = array();
$word = strtok($query, " ");
while ($word) {
if ($word[0] == '+') {
$word = substr($word, 1);
$requiredWords[] = $word;
}
if ($word[0] == '-') {
$word = substr($word, 1);
$forbiddenWords[] = $word;
}
if (!in_array($word, $foundWords)) {
$foundWords[] = $word;
search($file, $word, $results);
}
$word = strtok(" ");
}
$docs = array();
combine_results($results, $docs);
// filter out documents with forbidden word or that do not contain
// required words
$filteredDocs = filter_results($docs, $requiredWords, $forbiddenWords);
// sort the results based on rank
$sorted = array();
sort_results($filteredDocs, $sorted);
// report results to the user
report_results($sorted);
fclose($file);
}
示例2: search
function search()
{
if (strcmp('4.1.0', phpversion()) > 0) {
die("Error: PHP version 4.1.0 or above required!");
}
$paths = paths();
$files = array();
$j = 0;
for ($i = 0; $i < sizeof($paths); $i++) {
if (!($f = @fopen($paths[$i] . "search.idx", "rb"))) {
die("Error: Search index file could NOT be opened!");
continue;
}
$files[$j++] = $f;
if (readHeader($f) != "DOXS") {
die("Error: Header of index file is invalid!");
}
}
$query = "";
if (array_key_exists("query", $_GET)) {
$query = $_GET["query"];
}
//end_form($query);
echo " \n<div class=\"searchresults\">\n";
$results = array();
$requiredWords = array();
$forbiddenWords = array();
$foundWords = array();
$word = strtok($query, " ");
while ($word) {
if ($word[0] == '+') {
$word = substr($word, 1);
$requiredWords[] = $word;
}
if ($word[0] == '-') {
$word = substr($word, 1);
$forbiddenWords[] = $word;
}
if (!in_array($word, $foundWords)) {
$foundWords[] = $word;
for ($i = 0; $i < sizeof($files); $i++) {
do_search($paths[$i], $files[$i], strtolower($word), $results);
}
}
$word = strtok(" ");
}
$docs = array();
combine_results($results, $docs);
// filter out documents with forbidden word or that do not contain
// required words
$filteredDocs = filter_results($docs, $requiredWords, $forbiddenWords);
// sort the results based on rank
$sorted = array();
sort_results($filteredDocs, $sorted);
// report results to the user
report_results($sorted);
echo "</div>\n";
foreach ($files as $file) {
fclose($file);
}
}
示例3: main
function main()
{
if (strcmp('4.1.0', phpversion()) > 0) {
die("Error: PHP version 4.1.0 or above required!");
}
if (!($file = fopen("search.idx", "rb"))) {
die("Error: Search index file could NOT be opened!");
}
if (readHeader($file) != "DOXS") {
die("Error: Header of index file is invalid!");
}
$query = "";
if (array_key_exists("query", $_GET)) {
$query = $_GET["query"];
}
end_form(ereg_replace("[^[:alnum:]:\\.\\t ]", " ", $query));
echo " \n<div class=\"searchresults\">\n";
$results = array();
$requiredWords = array();
$forbiddenWords = array();
$foundWords = array();
$word = strtok($query, " ");
while ($word) {
if ($word[0] == '+') {
$word = substr($word, 1);
$requiredWords[] = $word;
}
if ($word[0] == '-') {
$word = substr($word, 1);
$forbiddenWords[] = $word;
}
if (!in_array($word, $foundWords)) {
$foundWords[] = $word;
search($file, strtolower($word), $results);
}
$word = strtok(" ");
}
$docs = array();
combine_results($results, $docs);
// filter out documents with forbidden word or that do not contain
// required words
$filteredDocs = filter_results($docs, $requiredWords, $forbiddenWords);
// sort the results based on rank
$sorted = array();
sort_results($filteredDocs, $sorted);
// report results to the user
report_results($sorted);
echo "</div>\n";
fclose($file);
}
示例4: main
function main($idxfile)
{
if (strcmp('4.1.0', phpversion()) > 0) {
die("Error: PHP version 4.1.0 or above required!");
}
if (!($file = fopen($idxfile, "rb"))) {
die("Error: Search index file could NOT be opened!");
}
if (readHeader($file) != "DOXS") {
die("Error: Header of index file is invalid!");
}
$query = "";
if (array_key_exists("query", $_GET)) {
$query = $_GET["query"];
}
$results = array();
$requiredWords = array();
$forbiddenWords = array();
$foundWords = array();
$word = strtolower(strtok($query, " "));
while ($word) {
if ($word[0] == '+') {
$word = substr($word, 1);
$requiredWords[] = $word;
}
if ($word[0] == '-') {
$word = substr($word, 1);
$forbiddenWords[] = $word;
}
if (!in_array($word, $foundWords)) {
$foundWords[] = $word;
search($file, $word, $results);
}
$word = strtolower(strtok(" "));
}
$docs = array();
combine_results($results, $docs);
// filter out documents with forbidden word or that do not contain
// required words
$filteredDocs = filter_results($docs, $requiredWords, $forbiddenWords);
// normalize rankings so they are in the range [0-100]
normalize_ranking($filteredDocs);
// sort the results based on rank
$sorted = array();
sort_results($filteredDocs, $sorted);
// report results to the user
report_results($sorted);
fclose($file);
}